sending data through serial cable


BeeHay

Recommended Posts

just looking for some help in trying to send a set of data in a format like this over a null modem cable -

example set -

&&

01404950.75

!!

01 = record number

40 = item number

4950.75 = channel value

i did make a new connection through comm monitor using com1 and used the NULL protocol...im just not sure on how to make it take my ch2 and send it to the receiving pc.

also would like to know how to make it on/off switchable...

would a serial breakout box be good for this? so i can monitor which pins are being used?

please, any info would be great.

Link to comment
Share on other sites

I'm afraid I don't completely understand your question. What is ch2? What do you mean by on/off switchable? Do you want to send this at a constant interval, and be able to turn off this constant update?

In general, the command you want is write():

device.mydevice.write("&&" + chr(13))

for example would output && plus a carriage return to the device named "mydevice" that you created with the NULL protocol.

The rest is just normal scripting. Use some of the string functions to create that 0140... number (I'd use format()), and perhaps a while() loop and delay() to create an repeating loop.

A breakout box isn't going to help much unless you have a scope, and then I'm not sure what you are going to do with it unless you know how to read serial, and well, why? Anyhow, you will find the comms going over pins 2 and 3. Normal, non-hardware handshaked RS232 serial lines use pins 2 and 3 for communications and 5 for ground. The rest are not used. In null modem, pin 2 of one side is connected to pin 3 and vica-versa and pin 5 is passed straight through.

Link to comment
Share on other sites

What is ch2?

our channel 2 on our daq board.

What do you mean by on/off switchable?

where we can turn the sending data on and off with a button.

Do you want to send this at a constant interval, and be able to turn off this constant update?

not sure what you mean, but this ouput needs to be real-time.

im sorry if i sound like a newb at this, but i am...

our pc with daqfactory needs to send our channel value over serial to a pc sitting right next to it...everyone i have talked to is like "thats simple"...yea, for those who know how...

all of our daq board readings and simple channel readings are working fine, now we just needs to send ONE channel (ch2) over serial and our bashing our heads in at this...

thanks for the reply...

Link to comment
Share on other sites

OK. First, I'm going to assume when you say:

&&

01404950.75

!!

you have a carriage return after each line, and that 01 and 40 are the same every time since you are just sending one channel. Here is what you do (note for other readers that you cannot do serial comm with Express. You must use Lite or higher. Express only works with the LabJack):

1) and you've already done this: create a new serial device by going to device configuration, New serial / Ethernet, creating a comm port and selecting the NULL protocol. Lets say you then gave this device the name "serout"

2) we're going to need a flag to turn this on and off, so create a new sequence, call it "StartUp" and put this one line of code in:

global SendDataOut = 1

do =0 if you want the default to be to NOT send data.

3) now, in your Ch2 channel, we are going to add an event. So, click on Ch2 in the workspace under CHANNELS: (you may have to expand the tree), then click on the Event tab in the new view. Put this code in the event tab:

if (SendDataOut)  
   device.serout.write("&&" + chr(13))
   device.serout.write("0140" + format("%07.2f",Ch2[0]) + chr(13))
   device.serout.write("!!" + chr(13))
endif

4) create an onscreen button to toggle SendDataOut between 0 and 1. Just use a button component and select Toggle Action.

This will output ch2 in the format you gave with every new data point. Note that this may slow your data acquisition. If ch2 is being read quickly (say > 10hz) you may see problems. There are ways around this (i.e. putting the output code in its own sequence so it runs concurrently).

To explain the code:

The first line checks the flag and if it is not 0, it then outputs

The next line writes the && and a carriage return. If your device requires a line feed instead, use chr(10). If both, then chr(13) + chr(10)

The next line is a little trickier, only because of the format() function. The format() function allows you to specify exactly how a number should be displayed. In your case, you want 7 characters, 2 decimals, and preceeded by 0's (i.e. 1.23 would be displayed as 0001.23). The format() parameters match exactly with the format parameters of the C printf() statement, and so anyone with any introduction with C should understand it. There are also loads of books, and of course our help which describe it as well.

The 4th line is basically the same as the 2nd, and the last line just closes the if.

Once you have it set up, use the monitor to see the data being sent out.

i just found the serialguide.pdf on the website, great read :)

Thanks. In your case though, I would not create a custom protocol and follow the lead I gave. If you were outputting multiple channels or were doing anything more advanced, you might want to move to putting the code into a protocol so it can be reused.

Link to comment
Share on other sites

thanks again for the help, REALLY apprecieate it!!!

here is what ended up working after a few hours of trial and error :)

if (SendDataOut)  
   device.serout.write("&&" + chr(13) + chr(10))
   device.serout.write("0140" + format("%04.1f",ch1*2000-10) + chr(13) + chr(10))
   device.serout.write("!!" + chr(13) + chr(10))
endif

i guess i did need those character returns and line feeds...

but for some reason i can't get the toggle button to work..

i have action channel as SendDataOut and toggle between 0 and 1...

also have a little LED there and in the expression box is CheckConnect(SendDataOut)

not sure if that is right, but that is not critical, the serial connection is working

woooo hooooo!!! :)

again, thanks!

Link to comment
Share on other sites

Yes, unfortunately serial communications is often about experimentation. Most device documentation has at least one or two vague portions. This is why when we write protocol drivers for customers we really have to have access to the device.

It sounds like you have the button setup correctly, but I don't understand why you put CheckConnect(SendDataOut) What is CheckConnect()? Really you just need to put SendDataOut as the expression of the LED since this should toggle between 0 and 1.

Link to comment
Share on other sites

well we have another led right above it to turn green/red when we connect the daq to Daqfactory and the expression in that led is CheckConnect(DevID[0]) and the led works when it is connected or not...the button has this Quick Sequence -

Connect(@devid)

SetScanType(devid[0], 05)

SetMultiChanScanChans(devid[0], 07)

SetDataLogOptions(devid[0], 02, 00, 00)

Rate =50

SendRate(devid[0], @Rate)

CheckConnect(devid[0])

so i thought CheckConnect(SendDataOut) would check to see if SendDataOut is 1 or 0 and would correspond with the green/red...

Link to comment
Share on other sites

Nope, CheckConnect is an external DLL call that you made, presumably to you lawson lab card's DLL. Actually, I think most of the commands you just showed are DLL calls from an extern().

You must be VERY careful about making this sort of mistake. You are basically making a call to a low level third party device DLL with a parameter that was essentially random. This could cause unpredictable behavior with your device, setting it into some weird mode, or even a normal mode that you don't realize and can't get out of. Its almost Russian roulette.

My general recommendation is: don't make function calls to functions you don't understand... For DAQFactory functions, you can look them up in the help file, but in this case, they are your functions, so you are on your own. OK, you didn't write the functions, but you imported them into DAQFactory using extern(), so only you know how they should be used. DAQFactory doesn't.

At this point, also, I'd cycle power on your computer / lawson lab device to ensure its in a power up mode and not some weird mode.

Link to comment
Share on other sites

yea, it does seem to take a long time (atleast 8-10 seconds) before the daq connects....and sometimes it takes longer and the system almost hangs when you connect it..

all in all, you have been a wonderful help and slowly but surely, i will get the hang of this stuff!!

:)

Link to comment
Share on other sites

  • 4 years later...

Thanks!! BeeHay!

I got it to Witts GAs over to Pason. Great.

Can someone help on how to parse the Data stream that comes back from Pason, in order to put Pason's numbers into a DF channel. I know every witts code has a number, like 0140 is 3rd party gas, and so on.

So in general there will be a 4 integer code preceding the values that I want to put into channels in DF, that comes from Pason-Rigwatch-Totco.

Here is an example of what comes back(Rx) each time I send 0140 to Pason.

Tx: &&1310

01400000.001310

!!1310

Rx: &&1310

1984PASON/EDR1310

0108964.231310

0110964.231310

011265.091310

0113248.251310

011531.891310

011712.241310

012070.231310

01212096.711310

012391.691310

012486.981310

0126450.001310

01280.001310

0171853.401310

!!1310

Rx: &&1310

1984PASON/EDR1310

0108964.231310

0110964.231310

011265.091310

Have you done this yet Beehay? Any Help much appreciated.

Thanks :)

Link to comment
Share on other sites

If I create an event like global readwitts=1

and I want to push values from the wiits device into channels in DF, how would I write that?

Device.serout.read(parse?? The data needs to be parsed.

I want to use the event tab in channels, for the witts device, like you showed in the example above.

something like:

if(readwits=1)

device.read_witts. read()

Or, create a new device that polls for the data stream? An example of the wiits stream is in my above reply/question.

Link to comment
Share on other sites

  • 3 months later...

Archived

This topic is now archived and is closed to further replies.