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.

SerialOut and DataTable


Steph Oct 8, 2008 11:09 AM

Hello,
in advance, sorry for my english...
I am using a CR1000 datalogger to register electric potential and temperature data on a volcano. We have 3 multiplexors (two for electric potential and one for temperatures).
I am trying to make the CR1000 communicate with the RS232 port in order to collect the data from this port.

The data I'm trying to send are 3 datatables corresponding to the data acquired from the 3 multiplexors. But I cannot find the syntaxe to use in the help of CRbasic, and I am noobie in CRBasic...


I added the commands as follow, in the .CR1 program, can you say me if it is correct?

SerialOpen (COMRS232,9600,0,0,10000)
(...)
SerialOut (COMRS232,A,B,C,0,0,100)

Where A, B and C are the DataTables names defined earlyer in the .CR1 file

If you need more info or to see the entire .CR1 file, let me know
thanks!!


IslandMan Oct 8, 2008 03:12 PM

Hello Steph,

Do you have Loggernet or CR400 software that will allow you to talk directly to the logger RS232 port and retrieve the data? That is typically the way you retrieve data, you don't have to set up the serial ports in the program.

Best Regards,
Dave (IslandMan)


Steph Oct 8, 2008 03:25 PM

Thanks for your reply!

We have installed a compact flash module on our CR1000 and we usually use the CP card to download the data (just for a try, we also connected our field computer to the RS232 port and downloaded the data with the PC400 software, there is no problem).
In fact, we need to send the data on the RS232 port because we would like to install a teletransmition system on the datalogger (this because our CR1000 is far from our lab and we can download the data directly from the datalogger only one time a month). The system usually used by my team for this kind of transmission, on the other stations of our network, uses the RS232 port. Sorry for the lack of explanation on this aspect, in my previous post.


IslandMan Oct 8, 2008 03:32 PM

Ok, Understand now.
Give me a little time and I'll post a solution here :-)


Steph Oct 8, 2008 03:37 PM

thanks a lot Dave!
If you need to see the .CR1 file, let me know...

Best regards,

Stéphanie


IslandMan Oct 8, 2008 04:14 PM

Steph,

You have the use the GetRecord to retrieve the data back into the logger from the output table to transmit it on the RS232 port. Following example records one minute average panel temp, checks to see that the output table was written then gets the record and sends it.

Good Luck,
Dave

'CR1000 Series Datalogger
'program author:IslandMan

'Declare Variables
Public Tref 'Panel Temp
Public OutString$ As String * 50 'String for GetRecord Results

'Table1 DataTable
DataTable (Table1,1,-1)
DataInterval (0,1,Min,10) 'Store data every minute
Average (1,Tref,FP2,False)
EndTable

'Main Program
BeginProg

Open the Serial Port
SerialOpen (COMRS232,9600,0,0,10000)

Scan (1,Sec,3,0)
PanelTemp( TRef,250)

'If the table has output, get the latest record
If Table1.Output(1,1) Then
GetRecord (OutString$,Table1,1)
'Send it out the serial port
SerialOut (COMRS232,OutString$,"",0,100)
EndIf

CallTable Table1

NextScan
EndProg


Dana Oct 8, 2008 04:54 PM

Also refer to the SendData instruction and example in the CRBasic help file. This instruction is supported by the CR1000, CR3000, and CR800 series.

Dana


jra Oct 8, 2008 05:18 PM

A note of caution about SerialOpen... Using this instruction:
SerialOpen (COMRS232,9600,0,0,10000)
will configure the datalogger's RS-232 port to communicate at 9000 baud.

If/When you use your software (LoggerNet, PC400, etc.) to connect to the datalogger on that RS-232 port you will need to match the baud rate. This is done through LoggerNet's Setup of the PakBus port in the Setup screen, or PC400's Datalogger settings.

Janet


IslandMan Oct 8, 2008 06:23 PM

Stéphanie,

One other caution:
Make sure the OutString$ length is long enough to accommodate the number of characters in your data table.

If you are still unsure, send the program to n2da@gmail.com and I'll have a look for you.

Regards,
Dave


Steph Oct 9, 2008 11:14 AM

Thanks for all the replies!!! Very good forum!

Dana
>>> I will have a look on this function and try it, after trying with the solution proposed by Dave.

Janet
>>> 9600 is the baud rate used by all the stations of my group, no problem.

Dave
>>> many thanks, I try to complete the program right now with your solution. However I have got a problem with the size of the outstring: I do not have access to this parameter. When I download the data from the station through the CP card, the program (PC400) does not allow me to see the string, it is automatically converted to .dat files.
From the documentation I know that the packet is composed of:
1 byte for the beginning of the packet
8 bytes for the header
x bytes for the message
2 bytes for the signature nullifier
1 byte marking the end of the packet

I try to find the number of bytes in the "message" and give you some news ASAP.
:D

Steph


IslandMan Oct 9, 2008 11:25 AM

Steph,

Each line in your .dat file would be the length of the string that you would have with GetRecord.

For Example:
"2008-09-09 09:00:00",0,4.337,206.9,18.74,73.65,88.1,69.94,1010.434,14.94
This record is 76 Characters including CR/LF at the end.

In program I would add a few to the length to be safe.
For above data I would set OutString$ to be 100.

Public OutString$ As String * 100

Hope this helps,
Dave


Steph Oct 9, 2008 01:57 PM

ok, I understand. The thing is I have 3 tables and I do not know how it is separated in the string. Most of all, in the .dat file, on different lines I can have different string length because values vary like: I can have a value of 5.678 or a value of 123.34 at the next sample, which is 5 characters for the first one and 6 for the second one.


So I see three solutions:

1- Is there a command to say "take all the data" instead of precising the number of characters of the outstring? In the help I read that defining the size is optional. What happen if I write Public OutString$ As String ?

2- You say I can add a few to the length definition of the outstring. Maybe it is a stupid question but... Why can't I add a lot to be sure? What happen if I define it as Public OutString$ As String * 800 and if in reality it is only 400 characters?


3- Last solution:
Is it possible to obtain the size of this part of the string before trying to send it on the RS232 port?
If I can obtain the size and place the corresponding number into a variable named A, can I then write Public OutString$ As String*A
I hope I'm not too vague...

One more time, thanks a lot for your time!

Steph


IslandMan Oct 9, 2008 02:25 PM

Steph,

If you have 3 different tables, you'll have to use GetRecord for each one to send them.

Are all the tables created at the same time or are they like 15 minute average, 30 minute average and 60 minute average?

If you don't tell the variable OutString$ how much to allocate I think it defaults to a very small number and not all of your table would fit into it.

You can only know the length of the string after you read it back in to memory with this example:
OutLength = Len(OutString$)
Since you have to declare the length of the string before the program runs, you can't use this method to adjust the variable OutString$ after the fact.

Making OutString$ as String * 1000 works, it just uses more memory in the logger. If you don't have a very large program it should be fine. It's better to have too much allocated than not enough :-)

Hope this helps.

Dave


Steph Oct 9, 2008 02:45 PM

All the tables are created at the same time: we sample the sensors every 5 minutes. We have 3 tables:
Table 1: 25 temperature records
Table 2: 32 electric potential records
Table 3: 32 other electric potential records
(the electric potentials are from 2 different types of sensors)

Ok now I think I've got all the necessary to complete the program. We'll try it next time we go to our station. Be sure I will keep in touch to inform you about the results.
I add your email adress to my contacts!
Many many thanks Dave!

Steph


Dana Oct 9, 2008 03:45 PM

So I see three solutions:

1- Is there a command to say "take all the data" instead of precising the number of characters of the outstring? In the help I read that defining the size is optional. What happen if I write Public OutString$ As String ?

I still suggest you look at SendData (ComPort, NeighborAddr, PakBusAddr, DataTable) before you implement a solution. There are a couple of advantages over using GetRecord:

* Less complicated programming (IMO)

* You don't have to grab a record from a data table and store it into a string (and thus, you don't worry about the size of Outstring :)

* You don't have to handle resending the string in the code if it should fail. When LoggerNet gets a SendData record, it looks for missing records and will automatically collect the "holes".

2- You say I can add a few to the length definition of the outstring. Maybe it is a stupid question but... Why can't I add a lot to be sure? What happen if I define it as Public OutString$ As String * 800 and if in reality it is only 400 characters?

The default size of a string if Size is not specified is 16. The larger the defined string, the more memory that is allocated at compile time. This ultimately affects the memory available for all variables (which is finite). Not really a big deal in a small program, but it could become a problem if you have a large program with many variables.

Regards,
Dana


Steph Oct 9, 2008 04:12 PM

It sounds good but there is something I do not know with this command:
The CR1000 will send the data to the RS232 from where we will teletransmit the data, via radiomodem, to a computer in lab. This computer is not dedicated only to this CR1000 so, if we can, we would like to avoid to install Loggernet or PC400 on it. We usually use Matlab for all the process of the data.

I began to use CRBasic... two days ago... and I don't know what to write for neighborAddr and PackbusAddr if we do not use Loggernet or PC400 to receive the data. Is there a special neighborAddr and PackbusAddr code when you use Matlab?

Steph

* Last updated by: Steph on 10/9/2008 @ 10:14 AM *


Dana Oct 9, 2008 07:12 PM

This computer is not dedicated only to this CR1000 so, if we can, we would like to avoid to install Loggernet or PC400 on it. We usually use Matlab for all the process of the data.

Then SendData would not work. I wasn't taking into consideration this requirement.

Regards,

Dana


Steph Oct 9, 2008 09:34 PM

It is good to know also that this solution exists with Loggernet and PC400. Thanks!

Stéphanie

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