Problem sending unsigned byte as string via "Serial Macro Extensions"

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem sending unsigned byte as string via "Serial Macro Extensions"

Graeme Awcock
I have been trying to output binary data (just an 8-bit unsigned character) from the ImageJ macro language in a form that can be sent over a serial link. I want to develop hardware that will use the data byte to control a DAC, for example. The problem is that a range of 16 values are being filtered out and replaced by another value…
I am using the "Serial Macro Extensions" as provided on the ImageJWIKI to control the serial port.
Mostly this works well, but something in the chain is 'filtering' out values in the range 80-9F hex. Instead the serial data in that range is forced to 3F hex (confirmed by hardware testing).
I am aware that this range of binary values corresponds to a block of control codes in Unicode/ASCII, so this seems like a likely motivation for the problem, but I need to get around it because I obviously want to be able to send all 256 possible values for the byte over the serial link.
I am using the built-in ImageJ macro function "fromCharCode(value)" to convert 'value' from hex to a string character. I do not know whether this function is filtering the characters 80-9F hex, or if it is happening within the serial macro extension code.
Can anyone help. please?
Reply | Threaded
Open this post in threaded view
|

Re: Problem sending unsigned byte as string via "Serial Macro Extensions"

Michael Schmid
Hi Graeme,

serial_ext.java uses String.getBytes() to convert the String into a  
sequence of bytes. From the Java Website:

public byte[] getBytes()
Encodes this String into a sequence of bytes using the platform's  
default charset, storing the result into a new byte array.
The behavior of this method when this string cannot be encoded in the  
default charset is unspecified.
So I would suggest that you change the code in serial_ext.java,  
roughly like this:

public void write(String s) {
     byte[] bytes = new byte[s.length()];
     for (i=0; i<s.length(); i++)
         bytes[i] = (byte)(s.charAt(i));
     write(bytes);
}


Michael
________________________________________________________________

On 28 Jul 2010, at 18:08, Graeme Awcock wrote:

> I have been trying to output binary data (just an 8-bit unsigned  
> character)
> from the ImageJ macro language in a form that can be sent over a  
> serial
> link. I want to develop hardware that will use the data byte to  
> control a
> DAC, for example. The problem is that a range of 16 values are being
> filtered out and replaced by another value…
> I am using the "Serial Macro Extensions" as provided on the  
> ImageJWIKI to
> control the serial port.
> Mostly this works well, but something in the chain is 'filtering'  
> out values
> in the range 80-9F hex. Instead the serial data in that range is  
> forced to
> 3F hex (confirmed by hardware testing).
> I am aware that this range of binary values corresponds to a block of
> control codes in Unicode/ASCII, so this seems like a likely  
> motivation for
> the problem, but I need to get around it because I obviously want  
> to be able
> to send all 256 possible values for the byte over the serial link.
> I am using the built-in ImageJ macro function "fromCharCode(value)" to
> convert 'value' from hex to a string character. I do not know  
> whether this
> function is filtering the characters 80-9F hex, or if it is  
> happening within
> the serial macro extension code.
> Can anyone help. please?
Reply | Threaded
Open this post in threaded view
|

Re: Problem sending unsigned byte as string via "Serial Macro Extensions"

Graeme Awcock
Hi Michael,

Thanks for getting back to me so soon.

Unfortunately, I am not a java programmer, and am just a newbie at
writing ImageJ macros, so I'm afraid I don't know how to do what you
suggest.  However, I do have a basic knowledge of programming
principles...

So far, I have merely downloaded the serial macro extensions from the
ImageJWIKI and then followed the instructions!  The only file involved
in that that is close to what you mention is "serial_ext.jar".  Can this
be modified in the way that you suggest, and if so, what can be used to
edit it?

Sorry to be so far off the pace!

Graeme

-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of
Michael Schmid
Sent: 28 July 2010 18:20
To: [hidden email]
Subject: Re: Problem sending unsigned byte as string via "Serial Macro
Extensions"

Hi Graeme,

serial_ext.java uses String.getBytes() to convert the String into a  
sequence of bytes. From the Java Website:

public byte[] getBytes()
Encodes this String into a sequence of bytes using the platform's  
default charset, storing the result into a new byte array.
The behavior of this method when this string cannot be encoded in the  
default charset is unspecified.
So I would suggest that you change the code in serial_ext.java,  
roughly like this:

public void write(String s) {
     byte[] bytes = new byte[s.length()];
     for (i=0; i<s.length(); i++)
         bytes[i] = (byte)(s.charAt(i));
     write(bytes);
}


Michael
________________________________________________________________

On 28 Jul 2010, at 18:08, Graeme Awcock wrote:

> I have been trying to output binary data (just an 8-bit unsigned  
> character)
> from the ImageJ macro language in a form that can be sent over a  
> serial
> link. I want to develop hardware that will use the data byte to  
> control a
> DAC, for example. The problem is that a range of 16 values are being
> filtered out and replaced by another value...
> I am using the "Serial Macro Extensions" as provided on the  
> ImageJWIKI to
> control the serial port.
> Mostly this works well, but something in the chain is 'filtering'  
> out values
> in the range 80-9F hex. Instead the serial data in that range is  
> forced to
> 3F hex (confirmed by hardware testing).
> I am aware that this range of binary values corresponds to a block of
> control codes in Unicode/ASCII, so this seems like a likely  
> motivation for
> the problem, but I need to get around it because I obviously want  
> to be able
> to send all 256 possible values for the byte over the serial link.
> I am using the built-in ImageJ macro function "fromCharCode(value)" to
> convert 'value' from hex to a string character. I do not know  
> whether this
> function is filtering the characters 80-9F hex, or if it is  
> happening within
> the serial macro extension code.
> Can anyone help. please?

___________________________________________________________
This email has been scanned by MessageLabs' Email Security
System on behalf of the University of Brighton.
For more information see http://www.brighton.ac.uk/is/spam/
___________________________________________________________

___________________________________________________________
This email has been scanned by MessageLabs' Email Security
System on behalf of the University of Brighton.
For more information see http://www.brighton.ac.uk/is/spam/
___________________________________________________________
Reply | Threaded
Open this post in threaded view
|

Re: Problem sending unsigned byte as string via "Serial Macro Extensions"

Michael Schmid
Hi Graeme,

it is easy - the sources are in the .jar file.
A .jar file is a .zip file (with a different name).

Just rename the .jar file to .zip, open/unpack it, put  
serial_ext.java from the .zip into your plugins folder, do the  
modification in the code, and use 'Compile and Run' of ImageJ.
If it compiles well, take the new serial_ext.class created by  
compiling and put it into the zip file, i.e., replace the original  
one. That's it. (You may rename it back to .jar, but that's not  
necessary, ImageJ also reads .zip files in its plugins folder.)

(I can't do it at the moment because I don't have RXTX on the  
computer where I am working.)
---
There was a mistake in my suggested code, an 'int' was missing in
     for (int i=0; i<s.length(); i++)

Michael
________________________________________________________________

On 29 Jul 2010, at 00:39, Graeme Awcock wrote:

> Hi Michael,
>
> Thanks for getting back to me so soon.
>
> Unfortunately, I am not a java programmer, and am just a newbie at
> writing ImageJ macros, so I'm afraid I don't know how to do what you
> suggest.  However, I do have a basic knowledge of programming
> principles...
>
> So far, I have merely downloaded the serial macro extensions from the
> ImageJWIKI and then followed the instructions!  The only file involved
> in that that is close to what you mention is "serial_ext.jar".  Can  
> this
> be modified in the way that you suggest, and if so, what can be  
> used to
> edit it?
>
> Sorry to be so far off the pace!
>
> Graeme
>
> -----Original Message-----
> From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of
> Michael Schmid
> Sent: 28 July 2010 18:20
> To: [hidden email]
> Subject: Re: Problem sending unsigned byte as string via "Serial Macro
> Extensions"
>
> Hi Graeme,
>
> serial_ext.java uses String.getBytes() to convert the String into a
> sequence of bytes. From the Java Website:
>
> public byte[] getBytes()
> Encodes this String into a sequence of bytes using the platform's
> default charset, storing the result into a new byte array.
> The behavior of this method when this string cannot be encoded in the
> default charset is unspecified.
> So I would suggest that you change the code in serial_ext.java,
> roughly like this:
>
> public void write(String s) {
>      byte[] bytes = new byte[s.length()];
>      for (i=0; i<s.length(); i++)
>          bytes[i] = (byte)(s.charAt(i));
>      write(bytes);
> }
>
>
> Michael
> ________________________________________________________________
>
> On 28 Jul 2010, at 18:08, Graeme Awcock wrote:
>
>> I have been trying to output binary data (just an 8-bit unsigned
>> character)
>> from the ImageJ macro language in a form that can be sent over a
>> serial
>> link. I want to develop hardware that will use the data byte to
>> control a
>> DAC, for example. The problem is that a range of 16 values are being
>> filtered out and replaced by another value...
>> I am using the "Serial Macro Extensions" as provided on the
>> ImageJWIKI to
>> control the serial port.
>> Mostly this works well, but something in the chain is 'filtering'
>> out values
>> in the range 80-9F hex. Instead the serial data in that range is
>> forced to
>> 3F hex (confirmed by hardware testing).
>> I am aware that this range of binary values corresponds to a block of
>> control codes in Unicode/ASCII, so this seems like a likely
>> motivation for
>> the problem, but I need to get around it because I obviously want
>> to be able
>> to send all 256 possible values for the byte over the serial link.
>> I am using the built-in ImageJ macro function "fromCharCode
>> (value)" to
>> convert 'value' from hex to a string character. I do not know
>> whether this
>> function is filtering the characters 80-9F hex, or if it is
>> happening within
>> the serial macro extension code.
>> Can anyone help. please?
>
> ___________________________________________________________
> This email has been scanned by MessageLabs' Email Security
> System on behalf of the University of Brighton.
> For more information see http://www.brighton.ac.uk/is/spam/
> ___________________________________________________________
>
> ___________________________________________________________
> This email has been scanned by MessageLabs' Email Security
> System on behalf of the University of Brighton.
> For more information see http://www.brighton.ac.uk/is/spam/
> ___________________________________________________________