Apéndice D.Programación en CRBasic
D.1Muestra del programa CR1000
El siguiente programa de muestra lee un conjunto de sensores 6150F con tres sensores biaxiales. El conjunto en este ejemplo se comunica con el CR1000 a través de los puertos de control C1 y C2, los cuales están configurados como COM1. Se necesita de un convertidor RS-485 a TTL. geokon ofrece el modelo 8020-38 para este propósito. Para obtener más información, consulte el Manual de instrucciones del modelo 8020-38.
Public ErrorCode |
'Error Code sent back from ModBus Command |
Public A_Axis_Degrees(3) |
'A Axis Degree Output |
Public B_Axis_Degrees(3) |
'B Axis Degree Output |
Public Celsius(3) |
'Temperature Celsius |
Public Count |
'Counter to increment through sensors |
'Define Data Tables
DataTable(Test,1,-1) |
|
||
|
Sample (3,A_Axis_Degrees(),IEEE4) |
'Store Degree Reading for A Axis |
|
|
Sample (3,B_Axis_Degrees(),IEEE4) |
'Store Degree Reading for B Axis |
|
|
Sample (3,Celsius(),IEEE4) |
'Store Thermistor C Reading |
|
EndTable |
|
'Main Program
BeginProg |
|||||
|
'Open COMport with TTL communications at 115200 baud rate |
||||
|
SerialOpen (Com1,115200,16,0,50) |
||||
|
|
'Read 3 sensors in MEMS String every 10 seconds |
|||
|
|
Scan (10,Sec,0,0) |
|||
|
|
|
'Loop through addresses of connected String For Count = 1 To 3 |
||
|
|
|
|||
|
|
|
|
'Reset temporary storage for both Degrees and Temp so not to retain |
|
|
|
|
|
'previous reading |
|
|
|
|
|
A_Axis_Degrees(Count) = 0 |
|
|
|
|
|
B_Axis_Degrees(Count) = 0 |
|
|
|
|
|
Celsius(Count) = 0 |
|
|
|
|
|
|
|
|
|
|
|
'Flush Serial between readings |
|
|
|
|
|
SerialFlush (Com1)
|
|
|
|
|
|
'Write to register to begin reading MEMS String |
|
|
|
|
|
NOTE: ModbusMaster won't send 0x118 unless "&H119" is 'entered |
|
|
|
|
|
|
|
|
|
|
|
ModbusMaster (ErrorCode,Com1,115200,Count,6,1,&H119,1,1,50,0) |
|
|
|
|
|
'Delay after write register |
|
|
|
|
|
Delay (1,1,Sec) |
|
|
|
|
|
|
|
|
|
|
|
'Use Modbus command to retrieve A Axis and B Axis Degree Readings |
|
|
|
|
|
ModbusMaster (ErrorCode,Com1,115200,Count,3,A_Axis_Degrees(Count),&H101,1,1,50,0) |
|
|
|
|
|
ModbusMaster (ErrorCode,Com1,115200,Count,3,B_Axis_Degrees(Count),&H103,1,1,50,0) |
|
|
|
|
|
|
|
|
|
|
|
'Use Modbus command to retrieve Thermistor Celsius from string |
|
|
|
|
|
ModbusMaster (ErrorCode,Com1,115200,Count,3,Celsius(Count),&H107,1,1,550,0) |
|
|
|
|
|
|
|
|
|
|
|
'Delay before proceeding to next reading |
|
|
|
|
|
Delay (1,1,Sec) |
|
|
|
|
Next |
||
|
|
'Call Table to store Data |
|||
|
|
CallTable Test |
|||
|
NextScan |
||||
EndProg |
El siguiente programa de muestra lee un conjunto de sensores 6150F con tres sensores direccionables. El conjunto en este ejemplo se comunica con el CR6 a través de los puertos de control C1 y C2, los cuales están configurados como ComC1.
Public ErrorCode |
'Error Code sent back from ModBus Command |
Public A_Axis_Degrees(3) |
'A Axis Degree Output |
Public B_Axis_Degrees(3) |
'B Axis Degree Output |
Public Celsius(3) |
'Temperature Celsius |
Public Count |
'Counter to increment through sensors |
'Define Data Tables
DataTable(Test,1,-1) |
|
||
|
Sample (3,A_Axis_Degrees(),IEEE4) |
'Store Degree Reading for A Axis |
|
|
Sample (3,B_Axis_Degrees(),IEEE4) |
'Store Degree Reading for B Axis |
|
|
Sample (3,Celsius(),IEEE4) |
'Store Thermistor C Reading |
|
EndTable |
|
'Main Program
BeginProg |
|||||
|
'Open COMport with RS-485 communications at 115200 baud rate SerialOpen (ComC1,115200,16,0,50,3) |
||||
|
|||||
|
|
'Read 3 sensors in MEMS String every 10 seconds Scan (10,Sec,0,0) |
|||
|
|
||||
|
|
|
'Loop through addresses of connected String For Count = 1 To 3 |
||
|
|
|
|||
|
|
|
|
'Reset temporary storage for both Degrees and Temp so not to retain |
|
|
|
|
|
'previous reading |
|
|
|
|
|
A_Axis_Degrees(Count) = 0 |
|
|
|
|
|
B_Axis_Degrees(Count) = 0 |
|
|
|
|
|
Celsius(Count) = 0 |
|
|
|
|
|
|
|
|
|
|
|
'Flush Serial between readings |
|
|
|
|
|
SerialFlush (ComC1)
|
|
|
|
|
|
'Write to register 0x118 to trigger string |
|
|
|
|
|
NOTE: ModbusMaster won't send 0x118 unless "&H119" is entered |
|
|
|
|
|
|
|
|
|
|
|
ModbusMaster (ErrorCode,ComC1,115200,Count,6,1,&H119,1,1,10,0) |
|
|
|
|
|
'Delay after write register |
|
|
|
|
|
Delay (1,1,Sec) |
|
|
|
|
|
|
|
|
|
|
|
'Use Modbus command to retrieve A Axis and B Axis Degree Readings |
|
|
|
|
|
ModbusMaster (ErrorCode,ComC1,115200,Count,3,A_Axis_Degrees(Count),&H101,1,1,10,0) |
|
|
|
|
|
ModbusMaster (ErrorCode,ComC1,115200,Count,3,B_Axis_Degrees(Count),&H103,1,1,10,0) |
|
|
|
|
|
|
|
|
|
|
|
'Use Modbus command to retrieve Thermistor Celsius from string |
|
|
|
|
|
ModbusMaster (ErrorCode,ComC1,115200,Count,3,Celsius(Count),&H107,1,1,10,0) |
|
|
|
|
|
|
|
|
|
|
|
'Delay before proceeding to next reading |
|
|
|
|
|
Delay (1,1,Sec) |
|
|
|
|
Next |
||
|
|
'Call Table to store Data |
|||
|
|
CallTable Test |
|||
|
NextScan |
||||
EndProg |