Aide pour une liaison serie

punch95 Messages postés 5 Date d'inscription mardi 21 janvier 2003 Statut Membre Dernière intervention 28 février 2003 - 28 févr. 2003 à 10:35
cedb002 Messages postés 151 Date d'inscription jeudi 27 février 2003 Statut Membre Dernière intervention 15 juin 2003 - 28 févr. 2003 à 11:06
J'ai trouvé un source c pour une liaison serie d'un beck sc12 et j'aimerai que l'on me commente le source si c possible merci.
/***************************************************************************/
// Example of using the fossil api.
//
// Created by Andre Pribil, on 11.05.2000
//
// Tested with Borland C/C++ 5.02 on a SC12 with Bios version 0.67
//
// Copyright Beck IPC GmbH
//
// Info: http://www.beck-ipc.com/chip
/***************************************************************************/

/***************************************************************************/
// Includes
/***************************************************************************/
#pragma option -1 // create 80186 code

#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
#include <ctype.h>

/***************************************************************************/
// Defines
/***************************************************************************/
#define PFE_INT 0xA2
#define HAL_INT 0xA1
#define TCP_INT 0xAC
#define BIOS_INT 0xA0
#define FOS_INT 0x14

/***************************************************************************/
// Variables
/***************************************************************************/
union REGS inregs;
union REGS outregs;
struct SREGS segregs;

/***************************************************************************/
// API sleep
/***************************************************************************/
void api_sleep(int ms)
{
// sleep
inregs.x.ax = 0x0900;
inregs.x.bx = ms;
int86x(TCP_INT, &inregs, &outregs, &segregs);
}

/***************************************************************************/
// Display command line options
/***************************************************************************/
void usage (void)
{
printf("\r\nFossil Demo V0.4");
printf("\r\nUsage: fosdemo <data> <stop> <flow> <rs485> ");
printf("\r\n port: 0=EXT, 1=COM");
printf("\r\n data: 7, 8");
printf("\r\n parity: N, E, O, M, S");
printf("\r\n stop: 1, 2");
printf("\r\n flow: 0=No, 1=RTS/CTS 2=XON/XOFF");
printf("\r\n baud: baudrate");
printf("\r\n rs485: 1 use RS485");
printf("\r\n pol: RS485 polarity");
printf("\r\n pin: RS485 TxEnable pin");
printf("\r\n\r\n NOTE: 2 Stop bits are only available when no parity is set");
exit(1);
}

/***************************************************************************/
// Main
/***************************************************************************/
void main (int argc, char *argv[])
{
char chr;
unsigned long i;
unsigned int rs485, rs485pol, rs485pin;
unsigned bits, parity, stop, port, flow;
unsigned long maxbaud, baud;
int divisor,div1,div2;
long baud1,baud2;
char * tr_string = "HELLO";

// Get timer base freq.
inregs.h.ah = 0x8A;
inregs.h.al = 2;
int86x(HAL_INT, &inregs, &outregs, &segregs);
maxbaud = (((unsigned long)outregs.x.dx<<16)+outregs.x.ax);

// Look at parameters
if (argc >= 7)
{
port = atoi(argv[1]);
if (port>1) usage();

bits = atoi(argv[2]);
if ((bits<7) || (bits>8)) usage();

chr = argv[3][0];
switch (chr)
{
case 'N': case 'n': parity=0; break;
case 'O': case 'o': parity=1; break;
case 'E': case 'e': parity=2; break;
case 'M': case 'm': parity=3; break;
case 'S': case 's': parity=4; break;
default : usage();
}

stop = atoi(argv[4]);
if ((stop<1) || (stop>2)) usage();

if ((parity) && (stop==2)) usage();

flow = atoi(argv[5]);
if (flow>2) usage();

baud = atol(argv[6]);
div1=(int)(maxbaud/baud);
baud1=(maxbaud/div1);
div2=div1+1;
baud2=(maxbaud/div2);
divisor= (baud1-baud) < (baud-baud2) ? div1 : div2;

if (argc>=8) rs485=atoi(argv[7]);
else rs485=0;

if (flow && rs485) usage();

if (argc>=9) rs485pol=atoi(argv[8]);
else rs485pol=1;

if (argc==10) rs485pin=atoi(argv[9]);
else rs485pin=0xFF;
}
else
{
usage();
}

// Display parameters
printf("\r\nInit %s with %d%c%d and %lu baud",
port ? "COM" : "EXT", bits, toupper(chr), stop, baud);
printf("\r\nBaud divider: %d\r\n",divisor);

// init fossil
inregs.h.ah = 0x04;
inregs.x.dx = port;
int86x(FOS_INT, &inregs, &outregs, &segregs);
if (outregs.x.ax != 0x1954)
{
printf("\r\nInit failed\r\n");
return;
}

// init baudrate
inregs.h.ah = 0x81;
inregs.h.al = bits-5; // data bits
inregs.h.bh = parity; // parity
inregs.h.bl = stop-1; // 1 stop bit
inregs.x.cx = divisor;// baud divider
inregs.x.dx = port; // port
int86x(FOS_INT, &inregs, &outregs, &segregs);

// Select RS485 pin
if (rs485pin != 0xFF)
{
inregs.h.ah = 0x82;
inregs.h.al = rs485pin;
inregs.x.dx = port;
int86x(FOS_INT, &inregs, &outregs, &segregs);
}
else
{
if (port==0) rs485pin = 10;
if (port==1) rs485pin = 5;
}

// init rs485
if (rs485)
{
printf("\r\nUsing RS485 mode, TxEnable=PIO%d, %s active\r\n",
rs485pin, rs485pol ? "High" : "Low");

inregs.h.al = rs485pol;
}
else
{
inregs.h.al = 0x2;
}
inregs.h.ah = 0x80;
inregs.x.dx = port;
int86x(FOS_INT, &inregs, &outregs, &segregs);

// init flow control
if (flow)
{
if (flow == 1) // RTS/CTS
{
inregs.h.al = 2;
}
if (flow == 2) // XON/XOFF
{
inregs.h.al = 9;
}
printf("\r\nUsing %s flow control\r\n", (flow==1) ? "RTS/CTS" : "XON/XOFF");

inregs.h.ah = 0x0F;
inregs.x.dx = port;
int86x(FOS_INT, &inregs, &outregs, &segregs);
}

// purge buffer
inregs.h.ah = 0x09;
inregs.x.dx = port;
int86x(FOS_INT, &inregs, &outregs, &segregs);
inregs.h.ah = 0x0A;
inregs.x.dx = port;
int86x(FOS_INT, &inregs, &outregs, &segregs);

// run about 1 min
for (i=0; i<6000; i++)
{
// Transmit char A
inregs.x.ax = 0x0141;
inregs.x.dx = port;
int86x(FOS_INT, &inregs, &outregs, &segregs);

// Transmit char B
inregs.x.ax = 0x0142;
inregs.x.dx = port;
int86x(FOS_INT, &inregs, &outregs, &segregs);

// Transmit block
inregs.h.ah = 0x19;
inregs.x.dx = port;
inregs.x.cx = 0x0005;
segregs.es = FP_SEG(tr_string);
inregs.x.di = FP_OFF(tr_string);
int86x(FOS_INT, &inregs, &outregs, &segregs);

// Read block of 1 char
inregs.h.ah = 0x18;
inregs.x.dx = port;
inregs.x.cx = 0x0001;
segregs.es = FP_SEG(&chr);
inregs.x.di = FP_OFF(&chr);
int86x(FOS_INT, &inregs, &outregs, &segregs);
if (outregs.x.ax)
{
printf("%c",chr);
}

api_sleep(1);
}

// deinit fossil
inregs.h.ah = 0x05;
inregs.x.dx = port;
int86x(FOS_INT, &inregs, &outregs, &segregs);

printf("\r\ndone");
}

2 réponses

cedb002 Messages postés 151 Date d'inscription jeudi 27 février 2003 Statut Membre Dernière intervention 15 juin 2003 1
28 févr. 2003 à 10:58
utilise le conposant mscomm il est beaucoup plus simple
0
cedb002 Messages postés 151 Date d'inscription jeudi 27 février 2003 Statut Membre Dernière intervention 15 juin 2003 1
28 févr. 2003 à 11:06
Demande chez festo, j'ai un technicien une fois qui avait plein de composant ocx pour les beck ipc
0
Rejoignez-nous