473,386 Members | 2,078 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,386 software developers and data experts.

About system( "mode com1 ...

I use system( "mode com1 : baud=9600 parity=n data=8 stop=1 to=off xon=off") to turn on com1 and send some data to MCU. Could anyone tell me how I can retrieve data from MCU without using C++ or MFC class or code?

Another que: Why the data showed in UltraEdit such as " 06 00 5b c6" is showed "06 00 ffffff5b ffffffc6" when using printf and %x ?

With great thanks!
Aug 30 '08 #1
3 3433
Banfa
9,065 Expert Mod 8TB
Look up the functions

CreateFile
WriteFile
ReadFile
BuildCommDCB
SetCommState

on MSDN (search in Google it's often the top result and Google search is better than MSDN site search)
Aug 30 '08 #2
Look up the functions

CreateFile
WriteFile
ReadFile
BuildCommDCB
SetCommState

on MSDN (search in Google it's often the top result and Google search is better than MSDN site search)
Thank you!
Do you have any suggestion on the second question?
Aug 30 '08 #3
Banfa
9,065 Expert Mod 8TB
Another que: Why the data showed in UltraEdit such as " 06 00 5b c6" is showed "06 00 ffffff5b ffffffc6" when using printf and %x ?
This looks like sign extension to me. When you have a negative value store in a variable in 2s compliment format ( which is what most computers use) the top bit is effectively the sign bit, set for negative numbers clear for positive numbers.

If you convert a signed integer type to another signed integer type with more precision, say signed char to signed int (taking ints as 4 bytes for this example) then if you just copied the bits from one type to the other the following would happen.

signed char sc = -1; // bit pattern 0xFF

copying to a signed int without sign extension would result in the bit pattern 0x000000FF or the value 255, not the desired result. Sign extension involves copying the value to the top bit of the lower precision value to all the upper bits of higher precision value so since the top bit of 0xFF is 1 the value 1 is copied to all the higher bits of the unsigned int resulting in the value 0xFFFFFFFF or the value -1.

This doesn't happen for unsigned variables as there is no sign bit, all the bits are value bits. However if you have values that should be unsigned but are held in signed variables if you convert them to a higher precision value you get unwanted signed extension.


When you call printf with its varidac function prototype the compiler does not know how to put the variables onto the stack for passing to the function. In this case all integer type variables with a lower precision than an int are automatically converted to int before they are placed on the stack.

I am guessing that you read the data from your file into a char (which is probably signed by default), then when you pass it to printf it automatically gets converted to an int resulting in unwanted sign extension.

You should either read the data in unsigned char if the data really is unsigned or you can fudge the printf call by casting the data to an unsigned char or unsigned int explicitly which will prevent the signed extension.
Aug 30 '08 #4

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

Similar topics

2
by: vince | last post by:
MSDN help says you can use a UNC path for any methods that accept a path, and I'm wondering if I can also substitute an IP address for the UNC....??? Example: Using System.IO.File.Move() ...
12
by: hykim | last post by:
Hello, everyone. according to MSDN, there is any constructor of System.DirectoryServices.SearchResultCollection Class. if I implement DirectorySearcher.FindAll() method by myself, then how can I...
3
by: msnews.microsoft.com | last post by:
actaully the code i have written below is pretty simple and short. no idea why it terminate at run-time with "An unhandled exception of type 'System.NullReferenceException' occurred" Thank you ...
1
by: ginee lee via .NET 247 | last post by:
(Type your message here) hi all, It seems that the arguments of System.Diagnostics.Process.Start()can only be the absolute path. The args can not be like".\abc\efg.exe" or "..\abc\efg.exe". While i...
0
by: mikelostcause | last post by:
Is there anyway to hold the base.WndProc(ref m) until after the Logout() function finishes loading a webpage?? I'm working on shutting down an app that runs in the system tray, I have no...
1
by: yogesh | last post by:
can anybody tell me about how linux detects that one perticular call is belonging to the which specific driver if possible give sequence of the events....
0
by: Netter | last post by:
I'm confused about: System.Windows.Forms.Cursor.Current = Cursors.WaitCursor Seems I read in this NG that it is not necessary to reset Cursor.Current because it gets reset automatically. Maybe...
0
by: Osamede Zhang | last post by:
I downloaded some web pages use System.Net.HttpWebResponse,and get string from it Like this: webresponse = (System.Net.HttpWebResponse)req.GetResponse(); System.IO.StreamReader stream =...
2
by: =?Utf-8?B?THVpZ2k=?= | last post by:
Hi all, in my web page (ASP.NET 2.0) I have this problem: is not allowed here because it does not extend class 'System.Web.UI.Page' and the page is this: REGISTRY PAG. ASP <%@ Page...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.