Talking to a serial device with a SNAP-PAC-R1


#1

I am wondering if anyone could provide some code assistance in how to get started with querying a serial device through Port 0 on a SNAP_PAC-R1. I have having some difficulty wrapping my head around the command seqence and structure to open the port, send a query command, accept the results and then parse out certain data from the return string. I haven’t been able to find too many code samples to follow. The one snippet that I did find showed how to use OPTO scripting to merge strings together, but I am looking for how to do the correct sequence of commands.

Thanks,
Vern


#2

Hi Vern
I am not sure of your skill set in writing optoscript code, but here is a sample of a simple loopback program. It is a beginning for you to get your head around things structure wise, and you can see it doing something. It is set for com port 0.

//sample code for sending and receiving data on a com port (loopback)
SetCommunicationHandleValue("ser:0,9600,n,8,1", spComHandle); //sets the com port number, baud, parity, data bits and stop bit

spStatus=OpenOutgoingCommunication(spComHandle);  //open the port

//if we have success then we will continue
if (spStatus==0) then
  /*****  TRANSMIT PART   *****/
  //clear the buffer
  ClearCommunicationReceiveBuffer(spComHandle);
  //build a string to send out the port
  TimeToString(spTxString);
  spTxString+=Chr(13);  //append a <CR> to the string (this will be our end-of-message terminator)
  //transmit the string
  spStatus=TransmitString(spTxString,spComHandle);

  /*****  RECEIVE PART   *****/
  //now lets receive the string we just sent
  //set the end-of-message terminator (this is the demarcation for strings) to <CR>
  SetEndOfMessageTerminator(spComHandle, 13);
  
  //check for data on the port and when we see some, exit (a timeout could be put here so an infinite loop doesnt occur)
  repeat
    spChars=GetNumCharsWaiting(spComHandle);
    DelayMsec(10);
  until (spChars>=0);

  //ok now we know there are chars there, read in the string
  spStatus=ReceiveString(spRxString, spComHandle);

endif

//close the com so we can do it all again
spStatus=CloseCommunication(spComHandle);

//the string in spRxString can now be parsed with some other code

What I do when working with any sort of communication data is to get familiar with the data structure using by either obtaining a manual/protocol or by using a terminal program to see (and log) the data. Once I am familiar with how the data is formatted, it makes it easier to visualize code structure.
Make sure you set the com port control function to ‘None’ in PAC Manager before using the above script. I think be default it is set for PPP.

If you can provide some examples I can try to assist you to achieve your goal.

Nick


#3

Thank you very much for the help. I will work with this today, and see how far I can get.

Vern


#4

Here’s a similar thread/example:
http://www.opto22.com/community/showthread.php?t=222


#5

Hello to everyone,
I’m just learning how to program the SNAP PAC R1. My question is following:

  1. Is it possible to manage SNAP PAC R1 via build in RS232 port using PAC Control Basic and Display Configurator Basic?
  2. Will it work via UHF radio?
    Actually I’ve followed to above mentioned link and got “Incoming!;data1;data2;info1;info2;” from the serial interface, but I don’t have any idea how to equal this interface functionality to Ethernet one.
    Thank you in advance for any help and reply.
    Sigma

#6

Hi Sigma,

Welcome to the forums! I’m not sure I completely understand you’re question(s), so let me tell you a couple things and ask you a couple more questions…

You mentioned UHF and an Ethernet interface. To communicate w/a device over Ethernet, you can use either tcp packets or not-yet-officially-supported) udp. The comm handle use would be very similar to that described above, but instead of “ser:…” your comm handle would start with “tcp:” or “udp:” and probably include an IP address and port of the device you’ll connect to. You’ll for sure want to check out the “Communication Handles” section of the PAC Control users guide (form 1700).

Not sure how a connection to a UHF radio would work, hoping others out there w/UHF experience will share.

The built-in serial ports on your SNAP-PAC-R or -S series controller can be used to exchange data as discussed above. Are you asking if you can connect your PAC Display via that port vs. the Ethernet interface? Is this a remote SNAP-PAC-R1 you’re trying to connect with that might be outside the range of a LAN or wireless network?

Any/all detail you can provide about what you’re trying to do would be helpful for getting you as many suggestions/ideas as possible. Do share!

Thanks,
Mary


#7

Hi mstjohn,
Thank you for your reply! I’ll try to provide more details. So an old CAC1200RTU telemetry unit installed at the marine buoy and communicating to onshore SCADA PC by UHF radio-modem via RS-232 serial interface. My task is replace obsolete one CAC1200RTU with OPTO22 SNAP PAC equipment and replicate the functionality from the old system without changing the radio. That because I’ve asked you about following:

  1. Is it possible to manage SNAP PAC R1 via build in RS232 port using PAC Control Basic and Display Configurator Basic?
  2. Will SNAP PAC R1 work on 19200b/s or 38400b/s speed via UHF radio?
    3.Can buildin Serial interface work in the same manner as ethernet port or it has limitations?
    I’ve got the SNAP PAC Learning Center unit, instructions and manuals from OPTO22 site and used them to understand the logic of SNAP PAC programming. The problem is that all these guides based on ethernet connection (which is up to date) and quite complicated explains how do all programming and controls by the serial interface. Do you have any easy solution how activate the serial interface and do all programming via this port (without eathernet connection).
    Thanks,
    Sigma

#8

Wow, well, this is not a trivial application, so I wouldn’t say we have an “easy solution.”

You can download strategies (from PAC Control) and talk to PAC Display via [B]PPP [/B]on the serial port. The PPP Interface gives you the IP address, then it just looks like you’re running over regular Ethernet. Folks use PPP for remote locations but that’s normally with a dial-up modem (you configure AT commands for example). But I don’t know if that would work w/a UHF radio-modem. Are you stuck w/that?

Also, you might want to contact our Product Support Group (support@opto22.com), as they may have worked w/someone else using a UHF device.

If you are stuck w/the UHF device, I’m guessing it’s very slow. It might be possible to have a PAC on either end of the connection, then pass minimal amounts of necessary data from the one PAC to the other. Then your onshore PAC can talk to PAC Display via Ethernet. But I’m making some assumptions here that might not be valid.

-Mary


#9

Maybe a serial to Ethernet converter in between the UHF and PAC would help? Something like a lantronix uds1100. One on each end would ensure from the PAC and software point of view they are connecting to an Ethernet network, not knowing there are radio waves inbetween?

Nick


#10

Hello Everyone,
I’m sorry for delay with answer. The most convenient way to solve the problem with usage of serial connection between radio-modem and SNAP-PAC-R1 controller has been solved by choose radio-modem equipped with RJ-45 Ethernet port. Thank you for all your posts.


#11

Hi pathfinder,
Thanks for reporting back on what you found!
-OptoMary