473,666 Members | 1,979 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Function inp / outp

Hello members,

i have a (time-(?))-problem with the serial-communication with an ms-
dos 6.2 and the rs232-interface with an rs485-adapter behind the
interface.

I program in C. As compiler, i am using Open Watcom to build a DOS 16-
bit executable.

When i send the telegram to the device, the device answers very fast
(<1 millisecond).
After complete sending, i set the rts to 0x0 and wait for the answer,
but i got no answer, or i am to slow.
Somewhere is the error.

Maybe someone has some ideas or can give me some tips for better
coding?

Thanks for your help.

Here is my complete code:

#include <stdio.h>
//#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <dos.h>
#include <time.h>

/*
* Define some program keys
*/

// Exit-States
#define EXIT_SUCCESS 1
#define EXIT_UNSUCCESS 0

/**
* Define some information which should be outsourced to a config file
*/

// Sum of devices at COM1
#define SUM_DEVICES_COM 1 1

/**
* Constants for serial port
*/

// Return values / Error codes
#define SERIAL_OK 1
#define SERIAL_E_COMPOR T_NOT_DEFINED -1
#define SERIAL_E_WRONG_ COMPT -2
#define SERIAL_E_WRONG_ COMORT -3

// Serial mode for register 3
#define SERIAL_MODE_5BI T 0x00 // Bit
0-1: 00
#define SERIAL_MODE_6BI T 0x01 // Bit
0-1: 01
#define SERIAL_MODE_7BI T 0x02 // Bit
0-1: 10
#define SERIAL_MODE_8BI T 0x03 // Bit
0-1: 11
#define SERIAL_MODE_1ST OPBIT 0x00 // Bit 2: 0
#define SERIAL_MODE_2ST OPBIT 0x04 // Bit 2: 1
#define SERIAL_MODE_PAR ITY_NON 0x00 // Bit 3-5: 000
#define SERIAL_MODE_PAR ITY_ODD 0x08 // Bit 3-5: 001
#define SERIAL_MODE_PAR ITY_EVEN 0x18 // Bit 3-5: 011
#define SERIAL_MODE_PAR ITY_MARK 0x28 // Bit 3-5: 101
#define SERIAL_MODE_PAR ITY_SPACE 0x38 // Bit 3-5: 111
#define SERIAL_MODE_BRE AK_CONTROL 0x40 // Bit 6: 0 or
1 Break control;
sends the receiver a break condition
#define SERIAL_MODE_ENA BLE_DLR 0x80 // Bit 7: 0 or
1 DLR access
enable; if set, registers 0 and 1 become one big word register (the
DLR)

/**
* Function-Prototypes
*/

int serialInterface Connect(int nComPort, const int nBaud, const int
nMode);
void serialInterface SetBaudrate(int nComPort, const int nBaud);
char serialInterface GetRegister(int nComPort, int nRegister);
void serialInterface SendData(int nComPort, char *cString, int nLen);
int serialInterface Connect(int nComPort, const int nBaud, const int
nMode);
int serialInterface GetPort(int nComPort);
void serialInterface SendTelegram(in t nCom, char cCommand, int
nSensor);
char vaseGenerateChe cksum(const char *cTelegram);

/**
* Functions / Routines
*/
int main(){

int i=1;
int c1=0,c2=0;
int input;
int ii=0, rts_delay=20000 ;

/* Connect to COM2 */
if(serialInterf aceConnect(seri alInterfaceGetP ort(2), 1200,
SERIAL_MODE_7BI T | SERIAL_MODE_2ST OPBIT | SERIAL_MODE_PAR ITY_EVEN)){
printf("Connect ed to COM2.\n");
saveToLog(DEBUG , "Connect to COM2.");

/* Connect to COM1 */
if(serialInterf aceConnect(seri alInterfaceGetP ort(1),
19200,
SERIAL_MODE_7BI T | SERIAL_MODE_2ST OPBIT | SERIAL_MODE_PAR ITY_EVEN)){
printf("Connect ed to COM1.\n");
saveToLog(DEBUG , "Connect to COM1.");

/**
* Initialise all devices
*/
printf("*** Initialise devices ***\n");
for(i=1;i<=SUM_ DEVICES_COM1; i++){
// for every device at com1

// Initialise sensor
printf("Activat e sensor %d.\n",i);
saveToLog(INFO, "Activate sensor " +
i);

serialInterface SendTelegram(se rialInterfaceGe tPort(1), 'T', i);

// Receive result
c1 = 0;
c1 = inp(serialInter faceGetPort(1) +
5);
// If so, then get Char
while(c1 & 1){
c2 =
inp(serialInter faceGetPort(1) + 0);
printf("IN %c
\n",c2); // Print Char to Screen
c1 =
inp(serialInter faceGetPort(1) + 5);
}// end while

// wait 500 milliseconds
delay(500);

// Get Version
printf("Get Version from sensor %d.
\n", i);
saveToLog(INFO, "Get Version from
sensor.");
saveToLog(INFO, i);


serialInterface SendTelegram(se rialInterfaceGe tPort(1), 'V', i);

// Receive result
c1 = 0;
c1 = inp(serialInter faceGetPort(1) +
5);
// If so, then get Char
while(c1 & 1){
c2 =
inp(serialInter faceGetPort(1) + 0);
printf("IN %c
\n",c2); // Print Char to Screen
c1 =
inp(serialInter faceGetPort(1) + 5);
}// end while
}// end initialise for every device
}
else {
printf("Error: Could not connect to COM1.\n");
saveToLog(ERROR , "Could not connect to
COM1.");
return EXIT_UNSUCCESS;
}
}
else {
printf("Error: Could not connect to COM2.\n");
saveToLog(ERROR , "Could not connect to COM2.");
return EXIT_UNSUCCESS;
}

return EXIT_SUCCESS;

}// end function main

int serialInterface Connect(int nCom, const int nBaud, const int nMode)
{
/*
* This function connect to an specified serial-port
*/
int nTmp = 0;

outp(nCom + 1, 0); // Turn off interrupts
outp(nCom + 3, 0x80); // SET DLAB ON
serialInterface SetBaudrate(nCo m, nBaud); // Set
baud rate

nTmp = nMode & 0x03;
if(nTmp == SERIAL_MODE_5BI T)
saveToLog(DEBUG , " SERIAL_MODE_5BI T");
if(nTmp == SERIAL_MODE_6BI T)
saveToLog(DEBUG , " SERIAL_MODE_6BI T");
if(nTmp == SERIAL_MODE_7BI T)
saveToLog(DEBUG , " SERIAL_MODE_7BI T");
if(nTmp == SERIAL_MODE_8BI T)
saveToLog(DEBUG , " SERIAL_MODE_8BI T");

nTmp = nMode & 0x04;
if(nTmp == SERIAL_MODE_1ST OPBIT)
saveToLog(DEBUG , " SERIAL_MODE_1ST OPBIT");
if(nTmp == SERIAL_MODE_2ST OPBIT)
saveToLog(DEBUG , " SERIAL_MODE_2ST OPBIT");

nTmp = nMode & 0x38;
if(nTmp == SERIAL_MODE_PAR ITY_NON)
saveToLog(DEBUG , " SERIAL_MODE_PAR ITY_NON");
if(nTmp == SERIAL_MODE_PAR ITY_ODD)
saveToLog(DEBUG , " SERIAL_MODE_PAR ITY_ODD");
if(nTmp == SERIAL_MODE_PAR ITY_EVEN)
saveToLog(DEBUG , " SERIAL_MODE_PAR ITY_EVEN");
if(nTmp == SERIAL_MODE_PAR ITY_MARK)
saveToLog(DEBUG , " SERIAL_MODE_PAR ITY_MARK");
if(nTmp == SERIAL_MODE_PAR ITY_SPACE)
saveToLog(DEBUG , " SERIAL_MODE_PAR ITY_SPACE");

nTmp = nMode & SERIAL_MODE_BRE AK_CONTROL;
if(nTmp == SERIAL_MODE_BRE AK_CONTROL)
saveToLog(DEBUG , " SERIAL_MODE_BRE AK_CONTROL");
nTmp = nMode & SERIAL_MODE_ENA BLE_DLR;
if(nTmp == SERIAL_MODE_ENA BLE_DLR)
saveToLog(DEBUG , " SERIAL_MODE_ENA BLE_DLR");

outp(nCom + 3, nMode);
outp(nCom + 2, 0xC7); // FIFO Control Register
saveToLog(DEBUG , "Turn off RTS.");
outp(nCom + 4, 0x0); // Turn off DTR, RTS, and OUT2

return SERIAL_OK;

}

void serialInterface SetBaudrate(int nCom, const int nBaud){
int nDivisor = 115200 / nBaud; // 0x1c200 / nBaud

// nDivisor defaults:
// ------------------
// 0x03 = 38,400 BPS
// 0x01 = 115,200 BPS
// 0x02 = 57,600 BPS
// 0x06 = 19,200 BPS
// 0x0C = 9,600 BPS
// 0x18 = 4,800 BPS
// 0x30 = 2,400 BPS
// 0x60 = 1,200 BPS

outp(nCom + 0, nDivisor); // Set Baud rate - Divisor
Latch Low Byte
outp(nCom + 1, 0x00); // Set Baud rate - Divisor
Latch High Byte

}

void serialInterface SendData(int nCom, char *cString, int nLen){
int i=0;
for(; i<nLen; i++){
outp(nCom + 0, cString[i]);
}// end for

}

int serialInterface GetPort(int nComPort){
/**
* This functions get the adress for the port
*/
int nPort = 0;

switch(nComPort ){
case 1:
nPort = 0x3F8;
break;
case 2:
nPort = 0x2F8;
break;
case 3:
nPort = 0x3E8;
break;
case 4:
nPort = 0x2E8;
break;
default:
return SERIAL_E_COMPOR T_NOT_DEFINED;
}

printf("Return for %d comPort %d.\n", nComPort, nPort);

return nPort;

}

void serialInterface SendTelegram(in t nCom, char cCommand, int nSensor)
{
/*
* This function sends a defined telegram over register 4
* to the sensor
*/

char cBuf[10];
char cChecksum;
char cTelegram[5];
int nLen;
int i = 0;

int c1, c2;

printf("Send Telegram for %d.\n", nCom);

// Build telegram data
cTelegram[0] = 'b';
cTelegram[1] = cCommand;
cTelegram[2] = nSensor + 48; // + '0'
cTelegram[3] = '\r';
cTelegram[4] = 0x0;

// Generate checksum
cChecksum = baseGenerateChe cksum((char*) &cTelegram[0]);

// Data to send
strcpy(cBuf, cTelegram);
nLen = strlen(cTelegra m);

cBuf[4] = cChecksum;
nLen++;
cBuf[5] = 0x0;
nLen++;

/*
* Send telegram to COM
*/
printf("Send telegram manually to OUT: %s\n", cBuf);
// printf("Telegra m is %d characters long.\n",nLen);

// Open RTS
outp(nCom + 4, 0x0B); // Turn on RTS

for(i=0;i<nLen; i++){
// Send data
printf("Data %c\n.", cBuf[i]);
outp(nCom + 0, cBuf[i]);
}

// Close RTS
outp(nCom + 4, 0x0); // Turn off RTS

} // end function

char baseGenerateChe cksum(const char *cTelegram){
int nChecksum = 0;
unsigned int i=0;

for(; i<strlen(cTeleg ram); i++) {
nChecksum = nChecksum ^ cTelegram[i]; // Jedes Zeichen
mit XOR
verknüpfen
}

// Letztes Zeichen muss ein \r (ASCII 13) sein.
if(cTelegram[strlen(cTelegra m) - 1] != '\r')
nChecksum = nChecksum ^ '\r';

nChecksum = nChecksum ^ 0xFF; // invertieren
nChecksum = nChecksum & 0x7F; // auf 7 Bit beschneiden
return (char) nChecksum;

May 10 '07 #1
22 14165
On 10 Mai, 14:28, Michael Post <michael.p...@p urematic.dewrot e:
Hello members,
......
is outp and inp the fastest way to communicate with the interface, or
other functions are faster?

Thanks for your help.

Michael

May 10 '07 #2
On 5ÔÂ10ÈÕ, ÏÂÎç8ʱ55·Ö, Michael Post <michael.p...@p urematic.dewrot e:
On 10 Mai, 14:28, Michael Post <michael.p...@p urematic.dewrot e:Hello members,

.....

is outp and inp the fastest way to communicate with the interface, or
other functions are faster?

Thanks for your help.

Michael
I think the inp() and outp() function is the fastest way to access the
interface in C language. Else you can use assembly language to access
the interface. Sorry for can't give you more help because I forgot the
detail about the UART interface. But I think a program written by C
can send data through COMM port in PC at a rate more than 921600bps.
So, I think may be you should check whether the receiver return the
answer signal. May be you need a oscilloscope or a logic analyser to
help you debug this program.

May 10 '07 #3
In article <11************ **********@p77g 2000hsh.googleg roups.com>,
Michael Post <mi**********@p urematic.dewrot e:
>i have a (time-(?))-problem with the serial-communication with an ms-
dos 6.2 and the rs232-interface with an rs485-adapter behind the
interface.
The standard C language only includes an fopen() function; if fopen()
is not sufficient to open the device conditioned to the right
communication parameters, then you will need to call upon system-
specific libraries that are beyond the scope of C.

To phrase this another way: what you have asked for cannot be done
in standard C, and you need to ask in a newsgroup specific to
your OS.
--
Is there any thing whereof it may be said, See, this is new? It hath
been already of old time, which was before us. -- Ecclesiastes
May 10 '07 #4
In article <f1**********@c anopus.cc.umani toba.ca>,
Walter Roberson <ro******@ibd.n rc-cnrc.gc.cawrote :
>In article <11************ **********@p77g 2000hsh.googleg roups.com>,
Michael Post <mi**********@p urematic.dewrot e:
>>i have a (time-(?))-problem with the serial-communication with an ms-
dos 6.2 and the rs232-interface with an rs485-adapter behind the
interface.

The standard C language only includes an fopen() function; if fopen()
is not sufficient to open the device conditioned to the right
communicatio n parameters, then you will need to call upon system-
specific libraries that are beyond the scope of C.

To phrase this another way: what you have asked for cannot be done
in standard C, and you need to ask in a newsgroup specific to
your OS.
To phrase this yet another way:

Nobody here gives a shit about you or your problems.

You may find some or all of the following links helpful in understanding
why this is so:

http://en.wikipedia.org/wiki/Aspergers
http://en.wikipedia.org/wiki/Clique
http://en.wikipedia.org/wiki/C_programming_language

May 10 '07 #5
Kenny McCormack skrev:
In article <f1**********@c anopus.cc.umani toba.ca>,
Walter Roberson <ro******@ibd.n rc-cnrc.gc.cawrote :
>In article <11************ **********@p77g 2000hsh.googleg roups.com>,
Michael Post <mi**********@p urematic.dewrot e:
>>i have a (time-(?))-problem with the serial-communication with an ms-
dos 6.2 and the rs232-interface with an rs485-adapter behind the
interface.
The standard C language only includes an fopen() function; if fopen()
is not sufficient to open the device conditioned to the right
communicatio n parameters, then you will need to call upon system-
specific libraries that are beyond the scope of C.

To phrase this another way: what you have asked for cannot be done
in standard C, and you need to ask in a newsgroup specific to
your OS.

To phrase this yet another way:

Nobody here gives a shit about you or your problems.
You made my day! haha haven't laughed that hard for some time...
Your evil-mindedness is funny ... but I still can't remember when I
started to appreciate good malice .. must since I started to read
comp.lang.c ...
and yes, I get it.. nobody gives a shit about it either...
You may find some or all of the following links helpful in understanding
why this is so:

http://en.wikipedia.org/wiki/Aspergers
http://en.wikipedia.org/wiki/Clique
http://en.wikipedia.org/wiki/C_programming_language
May 10 '07 #6
Carramba <us**@example.n etwrote:
Kenny McCormack skrev:
(trollspeak snipped)
*Please* ignore Mr. McCormack. He is neither pleasant nor helpful.

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gma il.com | don't, I need to know. Flames welcome.
May 10 '07 #7
In article <f1**********@c hessie.cirr.com >,
Christopher Benson-Manica <at***@faeroes. freeshell.orgwr ote:
>Carramba <us**@example.n etwrote:
>Kenny McCormack skrev:
(trollspeak snipped)

*Please* ignore Mr. McCormack. He is neither pleasant nor helpful.
Got ya on the run, don't I?

May 10 '07 #8
Michael Post wrote:
Michael Post <michael.p...@p urematic.dewrot e:

is outp and inp the fastest way to communicate with the interface,
or other functions are faster?
There are no such functions in C. Read the standard. See:

<http://cbfalconer.home .att.net/download/>

for a bz2 compressed version of N869.txt.

--
<http://www.cs.auckland .ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfoc us.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
<http://kadaitcha.cx/vista/dogsbreakfast/index.html>
cbfalconer at maineline dot net
--
Posted via a free Usenet account from http://www.teranews.com

May 10 '07 #9
Hello,

thanks all for your very explained versions of answers.
Thanks espacially to Kingfox for his answer.

The rest of answers are very shitty. This group is called comp.lang.c
and noch comp.lang.ansi-c

I have a problem with c ... ok, seems like not being in the ansi-
standard, but i hoped for a qualified answer here at this mailinglist
and not this shit.

When someone does not want to answer me then he should not do it, but
not answer with this non-productive text, because i search for a
qualified answer for my question and no answer like " youre shit and
we don´t want to answer it, cause it is no ansi".

Now i spurn this list and will not ask anymore any questions or other
phrases.

This is my meening.

Thanks for your genial welcome.

Michael

May 10 '07 #10

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

Similar topics

3
14929
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) { document.images.src = eval("mt" +menu+ ".src") } alert("imgOff_hidemenu"); hideMenu=setTimeout('Hide(menu,num)',500);
5
2824
by: phil_gg04 | last post by:
Dear Javascript Experts, Opera seems to have different ideas about the visibility of Javascript functions than other browsers. For example, if I have this code: if (1==2) { function invisible() { alert("invisible() called"); } }
4
1988
by: Adrienne | last post by:
I am the first to admit that I know bupkis about javascript, except that sometimes I need it to do something client side that I can't do server side. Anyway, here's my problem: <input type="text" name="ticket" id="ticket"> <input type="text" name="amount" id="amount"> My ASP script defaults ticket to be 30.00 and amount to be 600.00. What
2
7671
by: laredotornado | last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to have my Javascript function execute from the BODY's "onload" method, but if there is already an onload method defined, I would like mine to run immediately after it. So in the code below, what JS would i need to add to my "myfile.inc" page so that I could guarantee this behavior? <!-- main page --> <html> <head> <script type="text/javascript">
1
5267
by: suchitra | last post by:
Hello All I have interfaced some hardware to the parallel port of my pc and wish to communicate thru' C i am using the outp() function for that but the data i am sending is not reaching the port ! What may be the problem do i need to initialize the port ?
2
12681
by: sushil | last post by:
+1 #include<stdio.h> +2 #include <stdlib.h> +3 typedef struct +4 { +5 unsigned int PID; +6 unsigned int CID; +7 } T_ID; +8 +9 typedef unsigned int (*T_HANDLER)(void); +10
8
5094
by: Olov Johansson | last post by:
I just found out that JavaScript 1.5 (I tested this with Firefox 1.0.7 and Konqueror 3.5) has support not only for standard function definitions, function expressions (lambdas) and Function constructors (these three I knew about), but also conditional function definitions, as described in http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Defining_Functions ]. An example: function fun() {
3
3646
by: Beta What | last post by:
Hello, I have a question about casting a function pointer. Say I want to make a generic module (say some ADT implementation) that requires a function pointer from the 'actual/other modules' that takes arguments of type (void *) because the ADT must be able to deal with any type of data. In my actual code, I will code the function to take arguments of their real types, then when I pass this pointer through an interface function, I...
2
5173
by: amitppawar2007 | last post by:
#include <stdio.h> #include <conio.h> int main(void) { unsigned port = 0; int value; value = outp(port, 'C'); printf("Value %c sent to port number %d\n", value, port); return 0; }
0
8445
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...
0
8356
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
8871
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8640
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
6198
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
5664
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
4198
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...
1
2771
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
2
1776
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.