Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

CR1000 Poll and response with Hex characters


IslandMan Aug 28, 2009 11:17 AM

Hi All,
I have an inclinometer that uses hex characters for polling and subsequent response. I'm having a bit of an issue trying to figure out how to poll the sensor with the correct "string" output from the CR1000. The sensor has three axes and I'm interested in Axis 2 which is a poll command of 7F 01 83. 7F being the sensor address, 01 being the message length in bytes, less the address and length, and 83 which is the command for sending the Axis 2 data. I can connect the sensor to my PC and using the meta key programming in ProComm I can send the hex command and see the response so I know the sensor is working correctly. I've tried a bunch of different combination's of "strings" and cannot get the right combination so far. Any help would be appreciated.
Thanks,
IslandMan


GeodeNZ Aug 29, 2009 03:50 PM

Hi Island,

I've been working on a similiar project. I needed to adjust the set point value of an Omega process controller via a CR1000. This controller also sends and receives data using hex strings. I managed to write the software which will read and write the set point, though I see several coding issues I need to resolve.

I'm using an MD485 multidrop to connect to the controllers isolated RS485 interface.

Here's a link to the controller communication manual if you want to see the method to my madness. http://www.omega.com/manuals/manualpdf/M3397.pdf

Remember this code is just a start, it needs much more work but does read and write the setpoint, a good start so far.

Steve

'Omega controller to MD485 wiring
'Rx to MD485 terminal B
'Tx to MD485 terminal A
'Rtn to MD485 ground.
'
Public DecString
Public Expression
Public SetPoint_psig As Long
Public SetPressure_Flag As Long ' If Flag is set, then set pressure.
Public ReadSetPoint_Flag As Long ' If Flag is set, then read current setpoint.
Public Error_Flag As Long
'
Public HexString As String * 10
Public OutString As String * 10
Public InString As String * 10
Public Combined As String * 10
'
Public SetInjPres_psig As Long ' Value to set injection pressure with.

Const CR = CHR(13)

'==================================================================================================================
Sub ReadSetpoint
SerialFlush(ComSDC8)
InString = ""
OutString = "*01R01" + CR
SerialOut(ComSDC8,OutString,"",0,100)
SerialIn (InString,ComSDC8,100,13,100)
DecString = HexToDec(InString)
SetPoint_psig = DecString - 1048576
EndSub
'=== Subroutines to read and write Omega controller set point =====================================================
Sub WriteSetpoint
SerialFlush(ComSDC8)
Combined = "*01W01" + HexString + CR
SerialOut(ComSDC8,Combined,"",0,100)
Delay(1,100,mSec)
Combined = "*01Z02" + CR
SerialOut(ComSDC8,Combined,"",0,100) ' Issue controller reset command.
EndSub
'=== Bracket allowable range of 100 to 1500 +======================================================================
Sub ConvertInjPres
Error_Flag = 0
If SetInjPres_psig > 99 AND SetInjPres_psig < 1501 Then
Expression = 1048576 + SetInjPres_psig
HexString = Hex(Expression)
Else
Error_Flag = 1
EndIf
EndSub
'==================================================================================================================
'==================================================================================================================
BeginProg
SerialOpen (ComSDC8,-9600,0,100,50) ' Open communication port for MD485 >> Omega controller.
Scan(5,Sec,0,0) ' Measure every 5 seconds.
'--- Check read and write flags -----------------------------------------------------------------------------------
If SetPressure_Flag = 1 Then
ConvertInjPres
If Error_Flag = 0 Then
WriteSetpoint
ReadSetpoint
EndIf
SetPressure_Flag = 0
EndIf

If ReadSetPoint_Flag = 1 Then
ReadSetPoint : ReadSetPoint_Flag = 0
EndIf

NextScan ' Goto Scan.
'------------------------------------------------------------------------------------------------------------------
EndProg ' End program.


IslandMan Aug 30, 2009 10:22 AM

Geode,
Thanks for the reply. Looking through your program gave me some good ideas and understanding for solving my dilemma.
I'll post the solution when I get it working.
Rgds,
IslandMan

PS, I am finally able to get the sensor to respond by making my poll string like this:
Poll$ = CHR(127)+CHR(001)+CHR(131)

* Last updated by: IslandMan on 8/31/2009 @ 4:40 AM *


Sam Sep 1, 2009 02:40 PM

IslandMan,

I have run into a situation before where the serial sensor required a CR/LF before streaming data. In this particular instance I was only successful in sending the CR/LF when I declared it as follows:

Public CRLF as Long
CRLF = &h00000D0A


I would be interested in knowing if the following works for you sensor:

Public PollAxes2 as Long
PollAxes2 = &h007F0183

Sam


IslandMan Sep 1, 2009 03:03 PM

Hi Sam,

I tried your suggestion and the sensor does not respond.
I used:
PollAxes2 = &h007F0183
And also tried:
PollAxes2 = &h7F0183

I am polling through a SDM-SIO1, not sure if that makes a difference and I'm at OS17, just for the record.

Regards,
Dave


aps Sep 7, 2009 12:58 PM

Sending binary data out from the logger needs some thought. If you send values out directly without implicitly or explicitly converting them to strings then the raw binary value is sent. In the case of a long it will be a 4 binary bytes no matter what the long is assigned to. In the above examples this means some null characters will be sent in advance of the binary data you want which some sensors will ignore and other not.

You also need to be aware that the logger will convert most variables to strings before output the data if you append variables together in the serialout command, e.g. LongV+stringV will result in the long variable (longV) being converted to an ASCII representation of the number before it is transmitted before the stringV.

The most controlled way of sending a few characters is to use the chr function appending a serial of characters together if need be using the & or + operator. You can declare a constants too which helps with some understanding, e.g.

CONST CRLF = chr(13)+ chr(10)

which can then be appended to other data, e.g. stringV+CRLF or just used to send CR followed by LF.

Unfortunately some users might have found some issues with earlier logger operating systems when trying to build strings within the serialout instruction, using the + operator. This was a bug which was fixed at least two operating systems ago so you should find this all works now.


IslandMan Sep 9, 2009 10:46 AM

As it turns out, sending the correct poll was the least of my problems. Trying to read in the Hex answer with a SDM-SIO4 has proven to be a real hair puller. I still don't have it sorted out. Anyhow, thanks for the input Andrew.
IslandMan

Further Information:

Given a Poll of 7F 01 83 a example response would be 7F 01 83 FF FF 4E FF 27 where FF FF 4E FF is the data and 27 is the checksum. 2'Compliment and divide by 1000 and it equals -45.313.

I have tried SerialIn and SerialInBlock don't seem to work at all. SerialInRecord, trying to trap the 7F(127) and then dump the remaining characters into a string, works sporadically. I am using a SDM-SIO1 as this sensor is another one of those with "RS232" output that really isn't, TX Data needs to be in an ON state for the unit to work properly.
And finally the question:
Does anyone know if there are issues using Hex inputs with this device?

Thanks,
Dave

* Last updated by: IslandMan on 9/9/2009 @ 10:09 AM *


aps Sep 9, 2009 05:46 PM

The SDM-SIO1 (not SIO4 as mentioned once in your post) is relatively dumb and passes all the data through to the logger where it is processed in the same way as any other serial port on the logger so it is unlikely to be an issue.

Apart from checking your buffer size is big enough here are a couple of things that come to mind:

For serialinrecord can your checksum or data include the 7F value you are trying to use as the trigger to find the start of your data string - if so you are in trouble for obvious reasons.

As you are able to poll the sensor you should be able to use Serialinblock after issuing the poll and waiting for the data to get all the data back into one string which can then be broken down.

You then need to be careful how you deal with the string if the data values could include Null (chr(0)) characters for reasons discussed in other threads on this forum.


BTW when you say this is Hex data do you mean the data is transmitted as an ASCII Hex representation of the data (only using characters 0-9 and A-F) or are you using Hex just as a method of showing us 8 bit binary data. I am not sure?


IslandMan Sep 9, 2009 06:03 PM

Hi Andrew,
Sorry about the SIO1 & SIO4 mixup. My buffer is large enough, I've made sure of that. I now see what you mean about serialinrecord having an issue with multiple inputs of the trigger variable. I'll give Serialinblock another shot, I couldn't seem to get it to work though.
Yes, it's hex data, 0-9 & A-F.
Thanks,
Dave

Log in or register to post/reply in the forum.