鐳射激光器EzLaze3的二次開發




通信:RS232接口


命令語法

 <前綴><地址><命令串><參數><終止符> 

Field

Description

Prefix

一個分號字符“;”(59),必須放在所有命令的前面,當設備接收到前綴符後會重置命令輸入緩存區。

Address

兩個ASCII 字符,激光使用“LA” 作爲其地址

Command String

Commands are specific to each device -- see the following sections for the commands that each device supports.

Parameters

Some commands may have parameters which immediately follow the command string. Multiple parameters are separated by commas(逗號). You must supply the correct number of characters for all parameters under all circumstances. For example, if a command expects a three-digit value, then the parameter must in the form “000”, “001”… “100” etc.

Terminator

ASCII 回車字符(13),接受設備在終端沒有收到終止符時不會處理任何命令。


基本命令:

  • 能量          ;LAAT###   000-255
  •  頻率           ;LARR###   000-255
  •  激發模式     ;LAMO#     0連續 1單槍 2爆發
  • 鐳射指示燈   亮度 ;LASP###    000-255   是否閃爍  ;LASB#  0不閃 1閃爍  閃頻 ;LABR###  000-255  
  • 波長選擇     IR高低   ;LAHS#       1 低 2高     Green高低   ;LAHS#   3 低 5高   
  • 爆發次數    ;LABU####     0000-0050
  • 形狀(SlitX、SlitY):     ;LAXS###   ;LAYS###        000-255
  •  能量高 ;LAENH  能量低 ;LAENL
  •  鐳射開槍      ;LAGO   
  •  停止開槍      ;LAST  
  •  開啓激光      ;LAON  
  • 關閉激光       ;LAOF  
  • 計數   ;LASC  統計激光到當前時間爲止一共激發了多少次
控制流程
 初始化激光

打開串口

Send “;LASM1” 打開激光控制串口。激光會返回一個消息“ok”

 Send “;LASS” 檢查聯動裝置和電機的安全狀態,在處理前應等待電機移動位被清零

 若安全聯鎖裝置可靠, send “;LAON” 將激光置爲待機模式。

  保持通訊
當激光被打開後發送了“;LAON”命令必須定時(至少兩秒一次)發送命令給激光,否則激光會自動關閉。 使用了“;LASS”來定時間檢查激光狀態。
  發射激光

設定激光的能量、頻率、激發模式、波長、光圈 

Send “;LAGO” 發射激光 

Send “;LAST” 停止 發射激光 

Send “:LAOF”將激光置爲停止模式

程序實現

  1)  打開串口
      串口底層通訊調用的是開源的RS232控制源rs232.h與rs232.c,它所提供的函數
      int RS232_OpenComport(int comport_number, int baudrate, const char *mode)
     可以用來打開某個指定串口,三個參數分別代表串口號、波特率、通信協議。
    使用時設置 baudrate=9600,char mode[]={'8','N','1',0},當函數返回0時表示已成功打開串口
 2) 向串口發送信息
void RS232_cputs(int comport_number, const char *text)  /* sends a string to serial port */
{
  while(*text != 0)   RS232_SendByte(comport_number, *(text++));
}
        調用方法:RS232_cputs(cport_nr, ";LASS\n");   //發送 ";LASS\n" //檢查安全連鎖狀態
 3) 定時間檢查激光狀態
       採用多線程編程,爲查詢事件新建了一個線程。
          #include <pthread.h>
    int res; 
    pthread_t a_thread,b_thread; 
    res = pthread_create(&a_thread, NULL,thread_function,NULL); 
    if (res!=0) 
    { 
        printf("Create pthread error!/n"); 
        return 1; 
    }
交互界面

使用QT編寫gui界面



 




















發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章