serial communication code
moods from Lebanon  [5 posts]
8 year
I am trying to control a Pelco D protocol PTZ camera using rs-232 to 485 convertor and the serial module found in roborealm.

After connecting successfully to the COM / PORT / etc.....

if i write the Ascii code string for example"\255\1\0\16\0\5\22" which is turn left in the console of serial module and press send the PTZ with turn successfully.

but if i to call the Ascii code string from a variable set in VB scripts, it shoes that the console has took the value but the PTZ won’t move, WEIRD.

Tried 1:
if cogy <= (imageh / 2) - 10  then
SetVariable "key_to_sendy", Chr(92)+"255"+Chr(92)+"1"+Chr(92)+"0"+Chr(92)+"16"+Chr(92)+"0"+Chr(92)+"5"+Chr(92)+"22"

Tried 2:
if cogy <= (imageh / 2) - 10  then
SetVariable "key_to_sendy", "255/1/0/16/0/5/22"

both of these returns same value as the one i enter it manual in the console but only difference from manual input is that the PTZ doesn't move at all.

Attached pictures for more INFO.

Steven Gentner from United States  [1446 posts] 8 year

Its a question of formatting. When you specify \255 in the serial interface it knows that because you are entering in text that the \ means take the next number (255) and convert that into a single byte binary number. Thus only one 8 bit byte gets sent.

In the case of the variable, YOU are required to make that exact data. NO interpretation on the variable is done and the data is sent as is to the device. So, while you almost had it, try

SetVariable "key_to_sendy", Chr(255)+Chr(1)+Chr(0)+Chr(16)+Chr(0)+Chr(5)+Chr(22)

while will only send 7 binary bytes. The '/' is not needed since you are specifying data as-is to send without having the serial module interpreting the data inside the variable.

See if that works better.


moods from Lebanon  [5 posts] 8 year
didn't work at all :(
Anonymous 8 year
No...  my mistake.... it worked like a charm... thank you very much

This forum thread has been closed due to inactivity (more than 4 months) or number of replies (more than 50 messages). Please start a New Post and enter a new forum thread with the appropriate title.

 New Post   Forum Index