1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
| //*************************************************************************************************************************************
//
// Sample Program for Communicate (RS232)
//
// Target Machine : CPT-711
//
// Function:
// int SetCommType (int port, int type)
// Set the communication type of the port specified.
// Port 1 : 0 direct RS-232
// 1 docking(RS-485 communication)
// Port 2 : 2 via IR transceiver
// 3 standard IrDA communication
// 4 RF communication
// void open_com(int port, int parameter) : Initialize and enable specified the COM port.
// void write_com(int port, char *s) : Send a string out thuough the COM port.
// int com_eot(int port) : To see if any COM port transmission in process(End Of Transmission).
// viod close_com(int port) : To close specified communication port.
// int read_com(int port, char *s) : Read 1 byte from the COM port receive buffer.
//
// SYNTECH INFORMATION CO., LTD.
//
//*************************************************************************************************************************************
#define CODECLIENT_LONG 30
#define NUMCOMM_LONG 10
#define CODEARTICLE_LONG 18
#define DESIGNATION_LONG 60
#define QUANTITE_LONG 10
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "8300lib.h"
int iPort=1, iType=0, iBaudRate=0x08;
int beep1[4] = { 16, 5, 0, 0 };
void main (void)
{
char (*CodeClient)[CODECLIENT_LONG]; //tableaux de 30 char
char (*CodeArticle)[CODEARTICLE_LONG];
char Temp_NumCommande[NUMCOMM_LONG];
unsigned long int *NumCommande;
char (*Designation)[DESIGNATION_LONG];
char Temp_Quantite[QUANTITE_LONG];
char Temp_nbre_ligne[5];
unsigned long int *Quantite;
int i,num_commande=0;
int nbre_ligne=1;
int categorie_commande=0;
/*
int* NumCommande; //ints
char** CodeArticle; //tableau de 18 char
char** Designation; //tableau de 60 char
int* Quantite; //ints
int* Temp_NumCommande=(int*)malloc(10*sizeof(int));
char* Data=(char*)malloc(300);
int num_commande=0;
int iret,i, j;
*/
char cda, sda[100];
clr_scr ();
gotoxy (3, 0);
puts ("PROGRAMME DE TEST");
SetCommType (iPort, iType);
gotoxy (4, 2);
if (open_com (iPort, iBaudRate))
puts ("OPEN COM OK");
else
puts ("OPEN COM NG");
clear_com (iPort);
gotoxy (4, 6);
puts ("ENT POUR LIRE ");
while (getchar() != KEY_CR);
gotoxy (4, 6);
puts ("DEBUT DE LECTURE");
gotoxy (4, 4);
clr_scr();
//lecture nbrligne
i=0;
while(read_com (iPort, &cda))
{
if(cda == ';')
{
Temp_nbre_ligne[i]=0;
break;
}
Temp_nbre_ligne[i]=cda;
i++;
}
nbre_ligne=atoi(Temp_nbre_ligne);
printf("%d ",nbre_ligne);
while(getchar() != KEY_ESC);
clr_scr ();
//série allocation mem
CodeClient=malloc(nbre_ligne *CODECLIENT_LONG*sizeof(char));
NumCommande=malloc(nbre_ligne *sizeof(unsigned long int));
CodeArticle=malloc(nbre_ligne *CODEARTICLE_LONG*sizeof(char));
Designation=malloc(nbre_ligne * DESIGNATION_LONG * sizeof(char) );
Quantite=malloc(nbre_ligne *sizeof(unsigned long int));
ReadTry:
i = 0;
while (read_com (iPort, &cda))
{
if(cda != ';' && cda != KEY_CR )
{
switch(categorie_commande) //decoupage commande
{
case 0:CodeClient[num_commande][i]=cda;
break;
case 1:Temp_NumCommande[i]=cda;
break;
case 2:CodeArticle[num_commande][i]=cda;
break;
case 3:gotoxy(3,4);
printf("%d",i); //affichage bon i=8
printf("%c",cda); //affichage bon
Designation[num_commande][i]=cda; //erreur deja a i=7
gotoxy(i+2,2);
printf("%c",Designation[num_commande][i]); //bug ici, à i=8
while(getchar() != KEY_ESC);
break;
case 4:Temp_Quantite[i]=cda;
// a suprimer
printf("%c",Temp_Quantite[i]);
while(getchar() != KEY_ESC);
clr_scr ();
//
break;
default:break;
}
i++;
}
else
{
if(cda == ';')
{
//a supp
clr_scr ();
//
switch(categorie_commande) //decoupage commande
{
case 0:CodeClient[num_commande][i]=0;
break;
case 1:Temp_NumCommande[i]=0;
NumCommande[num_commande]=(unsigned long int) atol(Temp_NumCommande);
break;
case 2:CodeArticle[num_commande][i]=0;
break;
case 3:Designation[num_commande][i]=0;
break;
case 4:Temp_Quantite[i]=0;
Quantite[num_commande]=(unsigned long int)atol(Temp_Quantite);
break;
default:break;
}
categorie_commande++;
i=0;
if(categorie_commande >= 5)
{
printf("cat= %d et %d /n",categorie_commande,num_commande);
while(getchar() != KEY_ESC);
categorie_commande=0;
num_commande++;
}
}
}
}// fin boucle while lecture
ApEnd:
//clr_scr();
i=0;
gotoxy (4,2);
while (CodeClient[0][i] != 0)
{
putchar(CodeClient[0][i]);
i++;
}
putchar(';');
printf("%ld",NumCommande[0]);
putchar(';');
i=0;
while (CodeArticle[0][i] != 0)
{
putchar(CodeArticle[0][i]);
i++;
}
putchar(';');
i=0;
while (Designation[0][i] != 0)
{
putchar(Designation[0][i]);
i++;
}
putchar(';');
printf("%ld",Quantite[0]);
putchar(';');
gotoxy (4, 7);
if (close_com (iPort))
puts ("CLOSE COM OK ");
else
puts ("CLOSE COM NG ");
while (getchar() != KEY_ESC);
} |
Partager