473,326 Members | 2,337 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

05 Written To Serial Port?

Does the following code result in the hex value "05" being written to the serial port?

Expand|Select|Wrap|Line Numbers
  1.             int test21 = 0x05;
  2.             byte[] test = new byte[1];
  3.             test[0] = (byte)test21;
  4.             dexConnection.Write(test, 0, test.Length);
Jun 25 '08 #1
6 1225
Plater
7,872 Expert 4TB
Probably. Why cast it as an int first, why not start with a byte?
Jun 25 '08 #2
Probably. Why cast it as an int first, why not start with a byte?
I just find it easier to see clearly the hex value I am using to put it into an int variable like that. I think I may actually have some sort of problem with how it is being written to the serial port. When I hook up my pc running the application using the code I posted to write to the serial port, Hyperterminal on the other end show that it is receiving the character "P", and according to my ascii chart 05 in hex is equal to the ENQ character. Is "P" what I should be seeing on hyperterminal while using my code to write hex "05"?
Jun 25 '08 #3
Plater
7,872 Expert 4TB
There is nothing invalid about doing this:
Expand|Select|Wrap|Line Numbers
  1. byte test21 = 0x05;
  2. byte[] test = new byte[1];
  3. test[0] = test21;
  4. dexConnection.Write(test, 0, test.Length);
  5.  
If you are not getting the characters you think that you should, you might not be talking at the same baud rate?
Jun 25 '08 #4
There is nothing invalid about doing this:
Expand|Select|Wrap|Line Numbers
  1. byte test21 = 0x05;
  2. byte[] test = new byte[1];
  3. test[0] = test21;
  4. dexConnection.Write(test, 0, test.Length);
  5.  
If you are not getting the characters you think that you should, you might not be talking at the same baud rate?
Both PC's are running at a baud rate of 9600.
Jun 25 '08 #5
Plater
7,872 Expert 4TB
Both PC's are running at a baud rate of 9600.
Hmm, I dunno then. But I certainly would recomend not using int's cast to bytes if you can help it.

Unlike 0x01-0x04, 0x05 does not seem to be a printable character in hypreterminal (you can test with CTRL+E...or CTRL+A -> CTRL+D)
Jun 25 '08 #6
Hmm, I dunno then. But I certainly would recomend not using int's cast to bytes if you can help it.

Unlike 0x01-0x04, 0x05 does not seem to be a printable character in hypreterminal (you can test with CTRL+E...or CTRL+A -> CTRL+D)
My problem turned out to be a bad cable connecting to one of the devices I was trying to communicate with, resoldering of the cable fixed my problems.
Jun 27 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: willie | last post by:
Hi, I'm writing a program which requires the use of three serial ports and one parallel port. My application has a scanning devices on each port, which I can access fine with pyserial. ...
4
by: joe bloggs | last post by:
I am writing a mobile application to interface with a legacy system and I am planning to use web services to communicate with this system. The legacy system receives data through a serial port. ...
4
by: Frank | last post by:
Hello, how to get information about all serial ports in the PC? I use the following code, but i got only the data of the FIRST serial port. All other serial port information are not available...
13
by: Rob | last post by:
Hi all, I am fairly new to python, but not programming and embedded. I am having an issue which I believe is related to the hardware, triggered by the software read I am doing in pySerial. I...
6
by: terry | last post by:
Hi, I am trying to send a character to '/dev/ttyS0' and expect the same character and upon receipt I want to send another character. I tired with Pyserial but in vain. Test Set up: 1. Send...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.