473,811 Members | 2,631 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

serial programming plz explain

3 New Member
anyone can plz explain the code below....i have understood the basics of outortb and inportb but couldnt understand why and where specific hexcode values are used

#include<stdio. h> //header//
#include<conio. h> //header//
#include<dos.h> //header//
#include<graphi cs.h> //header//
#include<proces s.h> //header//
#include<time.h > //header//


#define PORT1 0x3f8 //port address//

unsigned char ca_data[25];

void portinit(void)
{
outportb(PORT1 + 1,0);
outportb(PORT1 + 3,0x80);
outportb(PORT1 + 0,0x0c);
outportb(PORT1 + 3,0x03);
outportb(PORT1 + 4,0x0B);
}

char* dwt(){
time_t t;
time(&t);
return ctime(&t);
}

void portclr(void)
{
char ch;
while(inportb(P ORT1 + 5) & 1)
{
ch=inportb(PORT 1);
}
}


void portread(int dnum,int timout)
{
int i=0,j=0;
while((i < timout) && (j < dnum))
{
delay(1);
if((inportb(POR T1 + 5) & 1))
{
if(j!=0)
{
ca_data[j]=inportb(PORT1) ;
j++;
}
else
{
ca_data[j]=inportb(PORT1) ;
if(ca_data[j]==0x65) //0x55
j++;
}

}
i++;
}
ca_data[dnum]=j;

}



void main(void)
{
int scan=0,device_1 =0,device_2=0,d num=12,timout=1 000;
clrscr();
printf("A Project on RFID System\n");
do
{
do
{
portinit();
do
{
portclr();
do
{
//printf("Scannin g...........\n" );
portread(dnum,t imout);
}
while(ca_data[dnum] < dnum);

}while((ca_data[0]!=0x65)||(ca_da ta[1]!=0x99));
printf("\nA Project on RFID System");
printf("\nScann ing............ ............... .....");

if(ca_data[3]==0x56)
device_1=1;
if(ca_data[3]==0x59)
device_2=1;

scan++;
}while(scan<5);
clrscr();
printf("A Project on RFID System\n");
printf("\nScann ing Results........ ...");
printf("\nAvail able Devices........ ..");
if(device_1==1)
printf("\nDevic e Name________Ele ctronic Notebook");
if(device_2==1)
printf("\nDevic e Name________Vac uum Cleaner");
printf("\nprese nt time________%s" ,dwt());
if((device_1==0 )||(device_2==0 ))
{
printf("\n\nDev ices Missing........ ..");
if(device_1==0)
printf("\nDevic e Name________Ele ctronic Notebook");
if(device_2==0)
printf("\nDevic e Name________Vac uum Cleaner");
sound(3000);
printf("\nprese nt time________%s" ,dwt());
printf("\nPress any key to Continue....... ..");
getch();
}
printf("\n\n\n_ _______________ _______________ ___");


device_1=0;
device_2=0;
scan=0;
//delay(1000);
}while(!kbhit() );

}


insight on below specific lines would be highly appreciated :

}while((ca_data[0]!=0x65)||(ca_da ta[1]!=0x99));
if(ca_data[j]==0x65) //0x55
Apr 10 '09 #1
5 2758
Banfa
9,065 Recognized Expert Moderator Expert
@kaushalneo
No we can't but I can explain why we can't. outportb writes directly to a memory location in the machine (you can't do this in WinXP, Vista or W7) so for instance I can see that your portinit function is writing 5 values to 4 separate locations in memory.

Now from the function name I would assume that it is initialising the hardware at those memory locations (probably 1 piece of hardware with several registers) but without knowing what that piece of hardware is and having access to its technical specification neither I nor anyone else can say what writing those specific values to those specific registers will do.
Apr 10 '09 #2
kaushalneo
3 New Member
thanks banfa for replying on this little piece of information that i have...


sir i m only initialising the com port by these commands and not the hardware in the portinit function and all the hexcode values in them are there for the registers of the UART for specifying the baud rate, parity, stop bits etc.

i took the pains to understand about those details and got them from the net...i must mention it took great pains to do even that

but as of this program i just need help on specific data values that are being returned which ofcourse my hardware would send.

for example i m referring to

while((ca_data[0]!=0x65)||(ca_da ta[1]!=0x99));

in this line i m unable to understand what 0x65 and 0x99 could possibly mean.


similarly

if(ca_data[3]==0x56)
device_1=1;
if(ca_data[3]==0x59)
device_2=1;

in this piece of code i m unable to get the significance of 0x56 and 0x59 and i suppose this would be the data that would come to my "COM port 1" and received from there.


for instance in the portinit function the hex values refer to as follows :

outportb(PORT1 + 3 , 0x80); /*Open Port*/
outportb(PORT1 + 0 , 0x0C); /*Baud Rate 9600*/
outportb(PORT1 + 3 , 0x03); /* 8 Bits, No Parity, 1 Stop Bit */
outportb(PORT1 + 4 , 0x0B); /* Turn on DTR, RTS, and OUT2 */

these all are pre-defined for the UART and do not refer to my hardware.


any further help would be greatly acknowledged
Apr 10 '09 #3
newb16
687 Contributor
Obviously, 0x56 and 0x59 are rfid tag ids stuck to notebook and vacuum. The hardware is supposed to issue 0x65 to its output and then up to 12 bytes (or until timeout expires), fourth of which is item's id. I'd rather start with reading this hardware's specs.
Apr 10 '09 #4
kaushalneo
3 New Member
heyy thanks newb16...ur info helped a lot really....

could u juz give me insight on 0x99 used in the same while loop.....

thanks in advance...

i ll try to geet the specs abt the hardware....and tell u the details and specifications of the same...
Apr 10 '09 #5
praveenmude
3 New Member
Hi the Port 1 defined with address 0x3F8 is the communications port COM 1 of the system, which is generally a printer port. You can find its specifications in any system from the system tools - system information. In the program, you are manipulating this COM 1 address and doing IO operations.
Apr 11 '09 #6

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

Similar topics

2
13203
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. However, I'm unsure of how exactly I should be designing the program, I thought I could use threading to start class: class scanner(Thread): def __init__(self,port):
1
4118
by: sarah | last post by:
hI, I have a project. I need to realise serial communication between PC and Altera FPGA in c or c++. The function of FPGA is working well. it can send data to uart. Does anybody know how to realise it in c or c++? Thanks
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...
4
2693
by: Duffey, Kevin | last post by:
I don't know if jdbc/java code requires this, but when I use two gui admin tools I found, and I insert a row into the table using their row editor feature, both require me to enter a number for the Serial type. I thought this type was used to auto-increment an id field and that I would not need to enter anything into it? Basically we need the normal indexed ID field for each table, and we want it to auto-increment. The serial shows a function of...
3
2056
by: Suchandra Thapa | last post by:
I was wondering if there was a reliable method to get the last id inserted into a serial column in a table. I believe previous recommendations given were to use a sequence, have your app get the nextval for the sequence and then use that in the insert. I was wondering if things had changed or if that is still the recommended method. -- Suchandra Thapa <s-thapa-11@alumni.uchicago.edu>
13
4836
by: Al the programmer | last post by:
I need to access the serial ports on my webserver from an asp.net page. I have no problem accessing the serial ports from a windows form application, but the code doesn't work in asp.net. I have been told it is not possible to access the serial ports from asp.net. The application is used to control custom hardware. The hardware is connected to a PC through serial ports. Our customer wants to control the hardware from a remote...
8
2470
by: vicky | last post by:
Hello,I met a question when I wrote the program.I want the program can transmit the data frame continuosly through the RS232 when the communication has been interrupted.But I don't know how to write. I don't know how to record.Who can give me hand?Thanks very much!
38
9674
by: shussai2 | last post by:
Hi, I am trying to access Serial Port in XP. I am using Dev-C++ IDE that uses Mingw as a compiler. I just want to know how I can open up serial port on COM1 and write some data. I have searched quite a bit over the web and could not find anything useful. I don't want to use Visual C++ or Cygwin, linux, etc. If any of you guys have some little tid bit of code that would be great to look at.
13
6215
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 am sending a short message to a group of embedded boxes daisy chained via the serial port. When I send a 'global' message, all the connected units should reply with their Id and Ack in this format '0 Ack' To be certain that I didn't miss a...
3
1840
by: ganesah | last post by:
hi there, could anyone please explain me on how to put the functions (e.g create file, open port, getcommstate,DCB, setcommstate, write and read file and commtimeouts in Win32 API) for serial communications in a right order....i do have the guidance from the msdn on the functions involved in creating serial communications but i don't know how to put them in a right format...like where the main functions should be and so on...please explain....
0
9730
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10403
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
10136
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...
0
9208
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6893
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
5555
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5693
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3868
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3020
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.