| Author |
Message |
fapplin
Joined: Jul 9, 2008 Posts: 5
|
Posted: Jul 9, 2008 3:24 PM Post subject: decoding numbers coming through serial port |
|
I have connected the BioEra software up to my serial port. I have a program on another computer sending me numbers in a round-robin fashion. The numbers have a range of 1-1000 and come in groups of 4 (each representing a different channel). For example, 385, 998, 223, 101 would represent numbers from channels 1 through 4 respectively and then the next group would come.
I took the SerialPort element and attached it to the Oscillate scope element just to see what I would get and after adjusting the range I was able to see something coming through. My question is: how would I get each number individually so I could use them?
Thanks,
Frank
btw - I'm new to BioEra and I'm not an electronics person, but I am a programmer. |
|
 |
jarek
Joined: Oct 22, 2007 Posts: 1075
|
Posted: Jul 9, 2008 3:36 PM Post subject: |
|
Frank,
first of all you need to make sure you properly synchronize sending/incoming numbers. Because the range 1-1000 indicates each of them requires at least 2 bytes (1 byte can hold up to 255)
So you need to know: 1. Is it always 2 bytes or more for each channel? 2. how each number is converted to two bytes (or more) in order to convert it back (could be little endian, big endian, signed, unsigned etc).
From SerialPort element you get the value of a single byte, not entire (multi-byte) number. So you have to concatenate them back into numbers. It could be useful to use Formatter for that once you know the format.
I would start first with NumericDisplay (with decimal display) to verify that you get right numbers.
Jarek
|
|
 |
fapplin
Joined: Jul 9, 2008 Posts: 5
|
Posted: Jul 9, 2008 3:40 PM Post subject: |
|
Hi Jarek,
The C# program is using 8-bit Unicode encryption and each number is a 32-bit int (so, 4 bytes). Does that help?
Frank |
|
 |
jarek
Joined: Oct 22, 2007 Posts: 1075
|
Posted: Jul 9, 2008 4:00 PM Post subject: |
|
In that case you can't use Formatter as now, because it can read only 1 or 2 byte numbers. I think I could extend it and add option to convert 4 byte number but it will take some time (week or two).
Jarek |
|
 |
fapplin
Joined: Jul 9, 2008 Posts: 5
|
Posted: Jul 9, 2008 4:37 PM Post subject: |
|
So, is there another way of putting the numbers together without using the Formatter element?
Frank |
|
 |
jarek
Joined: Oct 22, 2007 Posts: 1075
|
Posted: Jul 9, 2008 6:11 PM Post subject: |
|
Frank,
You could also use ExternalSource and handle data conversion in your code before delivering it to BioEra.
Is the serial port the only way to get your data from?
Jarek |
|
 |
fapplin
Joined: Jul 9, 2008 Posts: 5
|
Posted: Jul 9, 2008 7:38 PM Post subject: |
|
We could probably make it just 2 bytes. That should give us a range of 0 - 65000+. We don't need 32 bit. We could use just 16 bits. We'll try it and see.
Frank |
|
 |
jarek
Joined: Oct 22, 2007 Posts: 1075
|
Posted: Jul 9, 2008 9:00 PM Post subject: |
|
Yes, using just 2 bytes should allow to use current version of Formatter.
There is one thing which may not be important, but want to mention it just to make it clear. It looks like you don't have any type of synchronization between packets. So theoretically it could happen, that if one byte is lost for some reason, and then you will get invalid numbers (because your second byte will be in fact first of the next number etc, I think you get the picture). I don't know if that can happen in your case (if sender is started after the receiver it may work), but I thought to mention it, all devices for which I implemented drivers (using serial port) have some kind of packet synchronization/validation.
Jarek
|
|
 |
fapplin
Joined: Jul 9, 2008 Posts: 5
|
Posted: Jul 18, 2008 1:48 PM Post subject: |
|
Hi Jarek,
I'm just getting a chance to play with BioEra a bit again. OK. I have a Serial element, a Formatter element, and Numeric element. I am seeing the numbers being sent over the serial port from my C# program.
The C# program is sending the numbers in groups of 4 in a round-robin fashion - channel1Number, channel2Number, channel3Number, channel4Number, repeat, repeat, etc.
How would I get 4 Numeric elements to display the 4 different numbers coming over? I'm sure I'll more questions, but I am starting at the baby level.
btw- my electrical engineering friend loved the demos I showed him. He'll understand it all much better than me.
Frank |
|
 |
jarek
Joined: Oct 22, 2007 Posts: 1075
|
Posted: Jul 18, 2008 7:44 PM Post subject: |
|
Frank,
looks like your interface maybe too complex for regular bioera elements, it requires a preprocessing first. For most devices this is done in drivers, but it is also possible to build in CustomElement (see manual).
Since you are a developer, I think it would be rather easy for you to use java and implement a custom interface in your own java class using CutomerElement.
Please note: CustomElement has been improved recently, its latest version will be fully available in version 2.1.12 of BioEra (released hopefully tonight).
For now you can look at the documentation in manual. It contains a simple example which could be modified for your needs. In particular, 1. you will need to change number of output channels to 4. 2. Decode input data (connect the input of CustomElement to SerialPort) into 4 channels. 3. Compile java file and put class file in 'impl' folder.
Let me know if there is any problem or questions
Jarek
|
|
 |
jarek
Joined: Oct 22, 2007 Posts: 1075
|
Posted: Jul 19, 2008 12:23 AM Post subject: |
|
BioEra Trial 2.1 is now available, post here if you decide to try CustomElement and have any problems.
Jarek
|
|