• Post Reply Bookmark Topic Watch Topic
  • New Topic

Difference in writing bytes to OutputStream  RSS feed

 
Sezgin Carman
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

I am currently trying to access Plugwise energy meters.
I have working C# code, which I want to convert to Java code. The C# code just opens a serial port and writes a bytes-encoded command to the outputStream:



Now, I did the same in Java, but the command does not work:



The command switches off one plugwise node. When I run the C# code, this works. When I run the Java code, the code itself also seems to work. The code runs until the end without throwing an exception. But the plugwise node just does nothing.

What am I doing wrong?

Thanks in advance for any help!
 
Greg Charles
Sheriff
Posts: 3014
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to Java Ranch!

Wow, serial ports. I remember those. I haven't seen one for awhile, much less had to write to one. I thought of a couple things that might help though. First, you might try flushing that output stream before you close the port. It couldn't hurt anyway. Also, serial communications had all kinds of parameters, Baud rate, parity, flow control, data bits, check bits, etc. Maybe the C# defaults are more compatible with your serial port than the Java ones are? You could at least check them out, and make sure they all match. If that doesn't work, try dialing back the bit rate a bit. I remember that helping.

Now, I've got to go organize my floppy disks, then figure out how to jumper my hard drives.
 
Sezgin Carman
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much, Greg!
Adding the following code made it:


BTW, my "serial port" is at least connected via USB.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!