473,812 Members | 2,907 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Programming Serial Port

JT
I have been tasked with a project that needs to communicate with a
serial port device, a contactless smart card reader. In documentation
for the device, a sample code to compute the checksum for the packet
data is written in C.

I am not familar with C and can anyone tell me if the code i have
written to replicate the checksum method in C# is correct... Thanks in
advance.

C Method:
/**
* Syntax:
* U8 ComputeCheckSum (U8 *bDataLn, U8 bLength)
* Description:
* Compute the checksum for packet length and data packets.
* In:
* *bDataLn -> Pointer to the packet length byte of data packets
* bLength -> 1 for the packet length;
* number of bytes for the data packets
* Out:
* None
* Return:
* One byte of the final checksum.
* Usage:
* To calculate the packet length checksum:
* Eg., length = 0x09:
* U8 bCheckSum;
* bCheckSum = ComputeCheckSum (0x09, 1);
*
* To calculate the data checksum:
* Eg., data (hex string) is "\x05\x00\x10\x 00\x46" and data length = 0x05:
* U8 bCheckSum;
* bCheckSum = ComputeCheckSum ("\x05\x00\x10\ x00\x46", 0x05);
*/
U8 ComputeCheckSum (U8 *bDataLn, U8 bLength)
{
U8 i, bData = 0;
for (i=0; i<bLength; i++)
bData = bData - bDataLn[i];
return bData;
}

C# Method:
private byte ComputeCheckSum (byte[] pData, int pLength)
{
byte byteData = 0;
for (int i=0; i<pLength; i++)
{
byteData = (byte)(byteData - pData[i]);
}
return byteData;
}

Nov 16 '05 #1
0 1565

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
9096
by: ^CeFoS^ | last post by:
Hello to everybody, I've done an application that draws in a frame the trajectory of a robot. The robot position is readed through the serial port, and several commands are wrote through the same port to change the direction of the robot. The trajectory frame is managed by an applet, and the project works good when the applet is called by a html document allocated in the same local machine under W98 where the classes and the serial port...
3
4592
by: rusttree | last post by:
Many moons ago, I took a class in embedded control at school. The course focused on a micro-controller mounted on a small electric car that was programmed using simple C code. The micro-controller chip had several pins, some of which were for output and some were for input. The crux of the project was to make the program set the ouput pins to high or low to drive the servos and motors and read the input pins that were attached to various...
3
7446
by: Math55 | last post by:
hi, i have this piece of code: --- #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <termios.h> #include <stdio.h> /* baudrate settings are defined in <asm/termbits.h>, which is
1
1466
by: pei_world | last post by:
Hi there, I have search the web for serial port programming for age. I found some example codes. but I don't know how to test then. I don't have any idea how such program what undernearth. Can anyone give me some help? please add me on msn: pei_world@hotmail.com thanks in advanced
7
1822
by: Brian | last post by:
Can anyone help me to understand how to make VB .NET transmit text entered in a text box through a serial port while providing the user with the ability to select baud rate, parity, data bits, stop bits and comm port used from combo boxes?
4
11209
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. What I would like to do is make the serial port accessible via a web service. The web service and the legacy application would be running on the same machine. The mobile application would access the web service via a network connection. It...
6
1491
by: ken | last post by:
Hi all, I copied this code from the examples. "How to: Receive Strings From Serial Ports in Visual Basic" When I call the function and using the single step method it hangs at Dim Incoming As String = com1.ReadLine(). I don't have anything connect to Comm1. Does anyone know why this is happening? Thanks for the help. Regards, Ken Function ReceiveSerialData() As String ' Receive strings from a serial port.
4
17826
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 with this code sample: ManagementObjectSearcher searcher = new ManagementObjectSearcher("Select * from WIN32_SerialPort");
1
6093
by: Z.K. | last post by:
I know this is probably not the correct newsgroup, but I can't find anywhere else that is appropriate to post it in. I need to figure out how to write a bluetooth program to access a bluetooth barcode scanner. After a lot of searching the Internet, I have come to the conclusion that something using RFCOMM would be best. Unfortunately, Bluetooth programming books are not exactly plentiful and finding a book on RFCOMM is almost...
6
6672
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 '%' to serial port and make sure it reached the serial port. 2. Once confirmed, send another character.
0
9607
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10404
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10417
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10139
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7677
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6897
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5704
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4357
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3029
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.