06-14-2018 11:07 AM
Hello all
I am trying to read some data from a sensor that outputs via serial link. I have a generic USB to RS458 device (FTDI) and it appears as COM10. As far as I can see, this works with PuTTY just fine and just like any regular old serial interface.
I note Diadem 2017 DAC has a interface monitor. First I will see if my data appears there. But on-wards, there is not a straight forward way to get that data into the DAC system. I have read that you need to create a Script Driver for this. I have gone through generating the template, but I have to say, not being familiar with the scripting language, I haven't the first clue about how I actually get it to work.
Are there any examples I can look at? I just need it to read a data stream from serial. The device is popping out messages in this form at a rate of 10Hz:
$WI,WVP=007.5,195,0*7F
I am only interested in the middle numbers (007.5,195). I am building a DAC system that will sample that stream at whatever rate I choose.
Is there not a way you can build something in LabView and have DIAdem DAC use it?
Solved! Go to Solution.
06-18-2018 05:36 AM
Hi,
you can use the UDI object in DIAdem to read data from a serial port. I have attached a small DIAdem-DAC scheme and a script that you can use as a base to acquire data from your sensor. The script reads data from the serial port "COM10". It assumes that your sensor sends its data with 9600 baud, no parity, 8 data-bits and one stop bit. If your sensor uses different settings, you can change that in the script.
Best regards
Rainer
06-18-2018 06:06 AM
Hello Rainer
Very many thanks for taking the time to help me. I have been reading the DIAdem DAC script driver manual and getting a little lost with how to do things (but I am understanding the process better now). From looking, I take it DIAdem scripts aren't too far removed from visual basic?
Many thanks
Alex
06-21-2018 06:53 AM
Hi RainerH
This works a treat. Many thanks
I was looking to modify this to work by having the script send a query command to the sensor before reading. I need to reprogram the sensor to stop giving out updates continuously.
I think it should be straight forward by adding Call oUDM.Write ("query text",,0)
but I noticed this in the code you supplied me:
' read some data from the serial port to synchronize to the 1. value of the scan.
buffer = oUDIM.Read(1000,1)
What does this do exactly? I was worried that with the sensor outputting at 10Hz and the script running/saving data at 10Hz there would be chance of a miss-match in rates (hence switch to having the script query the port). But does that line solve that issue?
Many thanks
06-21-2018 09:51 AM
Ok, what am I doing wrong?
call oUDIM.ParamSet("Delimiter",(vbCR+vbLF))
call oUDIM.Write("$01,WV?*//",,1)
This is what I am trying to send to the sensor. If I send this via PuTTY or TeraTerm for example it works and the sensor responds. In Diadem script, it sends it and the return is blank.
I know I need to send Cr+Lf at the end of the query. This should work?
06-22-2018 02:03 AM
Just change
call oUDIM.Write("$01,WV?*//",,1)
to
call oUDIM.Write("$01,WV?*//")
this will automatically add the delimiter to the string sent.
Greetings
Rainer
06-22-2018 04:11 AM
Thanks RainerH
that worked
The issue next is, oUDIM.Read appears to be too slow.
At the moment I have just one instance of read. It reads the whole response instead of reading chunks and changing the delimiter each time. I don't know if this is faster, but it is how it is documented in the DAC script manual.
I am using#:
SensorMsg = oUDIM.Read(100,1)
so read 100 (bytes?) or until delimiter, which is CRLF in this case so I can read the whole thing. I am then trimming it, replacing the "=" with a "," and then splitting it into an array using delimiter of ",".
I used the script profiler and it it telling me CREATUDI.READ is taking just over 0.1 seconds to execute. I was aiming for a good 10Hz on this, but it seems 10Hz might be the absolute limit? and more likely ill get 8-9Hz at best.
I guess I am stuck?
06-22-2018 06:27 AM
Hi AlexMason,
I don't think that the read() function is the bottleneck that slows down your data acquisition over the serial line. I have this with a small script in DIAdem DAC. I sent out a string of 25 characters over COM1 and read it back immediately. At 9600 baud I got reached a sampling rate of about 38Hz which is within the expected range (9600 baud -> 960 characters/second ->38.4 messages/second). So one thing that will limit the maximum sampling rate is the time used for communication over the serial port. So the amount of data to be transferred and the baud rate used will limit the maximum achivable sampling rate. What baud rate do you use? Another point that may limit the achivable sampling rate is the sensor itself. As far as I have seen from your last post, you send a command to the sensor that triggers the data acquisition on your sensor. So what is the response time of the sensor to that commad? I guess the sensor will not respond immediately but will take some time before it sends the response. From your posts I see that you have to send a command of 12 characters (10 char + <CR><LF>) and you get back a resoponse of 24 characters. At 4800 baud you need at least 75ms for the data transfer. So your sensor will have to respond to the command in less than 25ms if you want to read out your sensor at 10Hz.
Greetings
Rainer
06-22-2018 06:38 AM - edited 06-22-2018 06:45 AM
Hi Rainer
The device uses 9600 baud. I think I can reconfigure it to be higher, but that may not solve the problem.
The device can contiually output at 10 Hz but of course that is not being requested. I shall check with the manufacturer what the response is. its a RS458 interface, so only half duplex.
In my code, i have write() followed immediately by read(). According to the script monitor, write takes 0.002 seconds and the read takes 0.1+ seconds.
I may be understanding this wrong but to me that looks like the sensor responds very quickly and the data arrives on the port. Reading whats on the port then takes a long time.
ETA: Changin baud rate is a simple job, so I will try that. The next speed setting is 19200. Is there a way to time the response?
06-22-2018 07:09 AM
ok changing the baud had no effect
I have attached a screen grab from the script monitor:
The time for 10 executions of read is just less than a second. This is the script running as fast as it can, not timed by a clock or anything.