| Author |
Message |
eliasb
Joined: Nov 23, 2006 Posts: 5
|
Posted: Nov 24, 2006 8:34 AM Post subject: NetworkClient / NetworkServer |
|
Quoting the manual:
[quote:026da6654f] NetworkClient
This object connects to a specified network server, and once a connection is established it exchanges scalar data through network. This can be any network server (not only NetworkServer available in BioEra), for example a web server. It is the logic contained in the design that handles communication properly. [/quote:026da6654f]
The information is not clear.
How can I write, say a C++ network client that will send scalar information to a NetworkServer?
What is a "scalar" data format??
Hope you provide me enough information to be able to write a C++ client that feeds data to BioEra
-- Elias |
|
 |
Jarek Foltynski
Joined: Jan 13, 2005 Posts: 62
|
Posted: Nov 25, 2006 12:26 AM Post subject: |
|
The NetworkServer or NetworkClient can receive/send single (raw) bytes only (1 byte, 8 bits this means values from -127 to 128). This is the most basic (low level) interface. In bioera scalar is up to 32 bits (4 bytes), so if you wish to exchange full range, then you need to take care of the format.
To communicate with C++ (or any other language) via TCP channel (network socket) those elements were prepared: XmlNetworkController and XmlNetworkServer. The XmlNetworkServer now only sends data out of bioera, but could be extended or XmlNetworkClient could be added.
There is yet another way to send data to bioera: ExternalSource. It allows custom programming in java, and it could implement for example custom tcp server.
Regards Jarek |
|
 |
eliasb
Joined: Nov 23, 2006 Posts: 5
|
Posted: Nov 25, 2006 8:58 AM Post subject: |
|
Hello Jarek,
Thanks for your useful reply.
[quote:cb8ffe6036] The NetworkServer or NetworkClient can receive/send single (raw) bytes only (1 byte, 8 bits this means values from -127 to 128). This is the most basic (low level) interface. In bioera scalar is up to 32 bits (4 bytes), so if you wish to exchange full range, then you need to take care of the format. [/quote:cb8ffe6036]
Please help me understand what is really sent so that I know how to interpret the data.
I wrote a small C++ echo server, and made a small EDFReader->RateLimit->(Osci, NumericDisplay, N_Client) Now all values within the signed byte range: -127 and 128 are correctly displayed by my C++ client.
Now BioEra seldom sends other value such as -187 which are displayed in the numericdisplay but my program has no way how to interpet the data.
I mean the received bytes should they be interpreted as one 1 or wait till they are 4 bytes, etc.....
How exactly are you sending to the network server from your Java client? say write(buffer, 1) <- to send one byte or you`re sending wither 1, 2 or 4 bytes?
2) [quote:cb8ffe6036] To communicate with C++ (or any other language) via TCP channel (network socket) those elements were prepared: XmlNetworkController and XmlNetworkServer. The XmlNetworkServer now only sends data out of bioera, but could be extended or XmlNetworkClient could be added. [/quote:cb8ffe6036]
Yes, the XmlNetServer works as described. Now why are the numbers from 0..1 or -1..1 and how do they relate to the value displayed in the numeric element? (we see numbers in, say, range -127..128) ? |
|
 |
Jarek Foltynski
Joined: Jan 13, 2005 Posts: 62
|
Posted: Nov 25, 2006 7:46 PM Post subject: |
|
Hi,
1.
At this moment in Network elements only one byte is sent, the lowest. It means that scalar value (32 bits) is casted to 8bits. Therefore all higher bytes are lost. There is no way to send all bytes, because there would be no information (on the receiving side) which is first. Such information is provided in XmlNetworkServer (as text), but here in socket we have only single 8 bit bytes. There is another element Formatter that might be used (it can pack 32 bits bytes into 4 separate bytes), but again there no synchronization here, so such transfer although might usually work, would not be fully reliable.
More about the cast: in NetworkServer byte value is converted from integer as unsigned (0 to 255). And in NetworkClient it is signed (-127..+128). I do not rember now why there is this difference, probably some historical requirements.
2.
The range 0 - 1 or -1 to +1 is adequate to percent range in NumericDisplay. It means that 100% is equal to 1. In BioEra each element can have its own custom defined signal range (viewable in Advanced Properties). So the value 1.0 means such nominal range. The range can be sometimes balanced (-1.0 .. +1.0) like in all EEG sources, or positive only (0 .. +1) for example after FFT has been calculated or ABS. This element has been designed like that to comply with some C++ application that bioera cooperate with, but it could be extended to send directly numeric value as well (if there is such need).
Jarek |
|
 |
eliasb
Joined: Nov 23, 2006 Posts: 5
|
Posted: Nov 26, 2006 12:24 PM Post subject: |
|
Hi,
1.
[quote] At this moment in Network elements only one byte is sent, the lowest. It means that scalar value (32 bits) is casted to 8bits. Therefore all higher bytes are lost. There is no way to send all bytes, because there would be no information (on the receiving side) which is first. Such information is provided in XmlNetworkServer (as text), but here in socket we have only single 8 bit bytes. There is another element Formatter that might be used (it can pack 32 bits bytes into 4 separate bytes), but again there no synchronization here, so such transfer although might usually work, would not be fully reliable.
More about the cast: in NetworkServer byte value is converted from integer as unsigned (0 to 255). And in NetworkClient it is signed (-127..+128). I do not rember now why there is this difference, probably some historical requirements. [/quote]
From what I understand then, when a scalar is sent through the network client and then received by the network server element, there is loss of information?
Check this design screenshot here:
http://lgwm.org/downloads/era1.gif
Notice that when the scalar is sent and received through the network the value is incorrect (if Fz+Pz is greater than a signed Byte range). However, if the value is not sent through the network client instead directly passed to a numeric display from the evaluator, then the Fz+Pz value is correct.
What do you advise?
For example, my goal is to have two BioEra on two machines, one that processes data and sends through a client element, and one BioEra on another machine that will receive the info and act accordingly.
[quote] There is no way to send all bytes, because there would be no information (on the receiving side) which is first [/quote] Sorry, I don`t understand what you mean. Can`t you send through the network the 4 bytes integer as is instead of just a single byte of it? Then in your documentation you say that we send 4bytes integer so the server should receive that much.
I meant something like: byte b[4] = new byte[4]; b[0] = Num & 0xFF; b[1] = (Num >> 8 ) & 0xFF; b[2] = (Num >> 16 ) & 0xFF; b[3] = (Num >> 24 ) & 0xFF; socket.Send(b); etc etc....
2.
[quote] The range 0 - 1 or -1 to +1 is adequate to percent range in NumericDisplay. It means that 100% is equal to 1. In BioEra each element can have its own custom defined signal range (viewable in Advanced Properties). So the value 1.0 means such nominal range. The range can be sometimes balanced (-1.0 .. +1.0) like in all EEG sources, or positive only (0 .. +1) for example after FFT has been calculated or ABS. This element has been designed like that to comply with some C++ application that bioera cooperate with, but it could be extended to send directly numeric value as well (if there is such need). [/quote]
Sorry, didn`t get you well,
Now taking the previous design as an example, however adding an XmlNetServer from the Evaluator`s output, then running my C++ client which supposedly shall receive the value of Pz+Cz, however I receive the range numbers as:
http://lgwm.org/downloads/era2.gif
Now how can I relate what you said to my problem? Where is the signal range defined in the advanced property?
3. I am asking all these questions just to clarify some things and try to solve the task at hand.
I will tell you my aim perhaps you can advise:
We need to create a design that will connect to a given device (say NeuroBit), then it (the design) shall pass the channel scalar value to a custom network client where additional computation is done (say a C++ client), then the result data should be passed to BioEra for further work.
So far: a. the NetworkServer/Client are not passing the complete value, instead they are truncated. b. XmlNetServer is passing some range value which I don`t understand its relation to the real needed value c. The ExternalSource just generates, instead I want it to have some input then emit some output, however the calculation should be free for me to write in any language.
Please advise.
-- Elias |
|
 |
Jarek Foltynski
Joined: Jan 13, 2005 Posts: 62
|
Posted: Nov 27, 2006 4:44 AM Post subject: |
|
Hi Elias,
> From what I understand then, when a scalar is sent through the network client and then received by the network server element, there is loss of information?
Yes that is correct if the value is besides 8 bits value. Those elements are the base level only.
> Sorry, I don`t understand what you mean. Can`t you send through the network the 4 bytes integer as is instead of just a single byte of it?
OK, let me clarify on example. Lets say that we send 4 bytes as you suggest. Then for some (network related) reasons, the one of those four bytes is lost during network transmission (it can happen rarely but it is possible). The receiver doesn`t know about it and will build all next scalar values starting from another (not first) byte, therefore making all values totally invalid.
As I mentioned, you can do exactly what you propose with using Formatter (it can pack now scalars only up to 2 bytes, but if you ask then in the next version I can add option to do this with 4 bytes). You can connect it after NetworkServer and before NetworkClient and do oposite operation. But this will not be fully reliable because of the reasons I provided above.
2.
> Now how can I relate what you said to my problem? Where is the signal range defined in the advanced property?
If right-click on the XmlNetworkServer element, then select from drop down menu "Advanced Properties" and select tab "Signal Parameters" you will see that. You will see digital range and physical ranges. The 1.0 is equivalent to "Digital Max" or "Physical Max" values (first describes integer range, the second corresponding physical range).
For example if Digital Max is 256, and Physical Max is 100, then 1.0 means 256/100, 0.5 means 128/50 and so on. Let me know if that is still not clear.
> What do you advise?
A.
If you need to exchange full range data, then I think the best at this moment would be to use XmlNetworkServer. I can explain more if the above is not clear enough. You will need to build a simple xml parser.
B.
It would be also possible to use Evaluator, and inside there use java Socket to send directly to your C++ application in whatever format you like. It would be a few lines of code to build custom network client.
C.
You could also use Evaluator, convert data from integer to 4 bytes (as you proposed), and send it to Network elements.
I personally recommend XmlNetworkServer because it is already tested, but it is up to you. I understand you also need information back to bioera, and that is not available in this element if you need a fully streamed data (I will add to this option to the list of new features). It depends what exactly you need to send back.
Let me know if I can answer more questions.
Jarek |
|
 |
eliasb
Joined: Nov 23, 2006 Posts: 5
|
Posted: Nov 28, 2006 9:02 AM Post subject: |
|
Hello Jarek,
Thanks for your replies, they helped alot.
[quote:fcbbdf04bd] If right-click on the XmlNetworkServer element, then select from drop down menu "Advanced Properties" and select tab "Signal Parameters" you will see that. You will see digital range and physical ranges. The 1.0 is equivalent to "Digital Max" or "Physical Max" values (first describes integer range, the second corresponding physical range).
For example if Digital Max is 256, and Physical Max is 100, then 1.0 means 256/100, 0.5 means 128/50 and so on. Let me know if that is still not clear. [/quote:fcbbdf04bd]
Please give me some more examples.
So say the Pmax = 100, Dmax = 256, Pmin = -100 and Dmin = -256, and the XML reads: 1) 0.512312 = v1 and the original scalar was s1 2) -0.12321 = v2 and the original scalar was s2
How can I get back s1 and s2 in formula wise?
[quote:fcbbdf04bd] You could also use Evaluator, convert data from integer to 4 bytes (as you proposed), and send it to Network elements. I personally recommend XmlNetworkServer because it is already tested, but it is up to you. I understand you also need information back to bioera, and that is not available in this element if you need a fully streamed data (I will add to this option to the list of new features). It depends what exactly you need to send back. [/quote:fcbbdf04bd]
Since you suggested that I can use Sockets in the evaluator, then I can: 1) Initialize the connection 2) Send to my server the scalar value(s) 3) my server processes the values 4) the Evaluator can wait for a response 5) the Evaluator receives back from server 6) the evaluator writes the the values back and bioera can use them
A) Looks possible to do processing outside BioEra then returning the values?
B) Now what happens if the evaluator sends to the server, and then waits for a reply. Now the server delays for 5 seconds, will BioEra block? (given that the socket is in synchronous mode) ?
C) As I remember, I ran a test with the EDFReader -> (NetworkClient / Server and with a numeric display), then to numeric display directly w/o passing through the network. I noticed that the direct numeric display is faster than the one that is connected to the network.
Does my observation have something correct to it? |
|
 |
Jarek Foltynski
Joined: Jan 13, 2005 Posts: 62
|
Posted: Nov 28, 2006 10:13 PM Post subject: |
|
Hi Elias,
> So say the Pmax = 100, Dmax = 256, Pmin = -100 and Dmin = -256, and the XML reads: > 1) 0.512312 = v1 and the original scalar was s1 > 2) -0.12321 = v2 and the original scalar was s2
For digital values: s1 = 0.512312 * Dmax s2 = -0.12321 * Dmax (or -(-0.12321) * Dmin)
For physical values, the same but with physical ranges. The same number can be interpreted as digital or physical value in the same time.
> A) > Looks possible to do processing outside BioEra then returning the values?
Yes
> B) > Now what happens if the evaluator sends to the server, and then waits for a reply. > Now the server delays for 5 seconds, will BioEra block? (given that the socket is in synchronous mode) ?
Yes it should work, but you need be careful about that, because that is not recommended. BioEra is real time system and single threaded, it means that element in design should never block for longer then 1 second.
If something requires blocking then a Thread should be used or .available() method for reading from Socket (which allows to process only data that is available wihout blocking). Those techiniques are used often in various elements, but all of that becomes more complicated and requires more java knowledge. That is why I recommended using XmlNetworkServer, because it already has all of that and is tested. The same is with NetworkServer, it has internal threads which allows to listen and process data simultaneously.
So general idea is: use Evaluator only if necessary and minimally. If you need socket, then better use Network elements connected to output/input of Evaluator, because they never block.
> C) > As I remember, I ran a test with the EDFReader -> (NetworkClient / Server and with a numeric display), then to numeric display directly w/o passing through the network. > I noticed that the direct numeric display is faster than the one that is connected to the network. > Does my observation have something correct to it?
It definitely should be faster because there network layer adds some delay, but that should not be big difference.
Jarek |
|