int far pascal zOpenComm( LPCSTR pp1, UINT pp2, UINT pp3 ) { int r; SaveRegs(); /* ** Log IN Parameters (No Create/Destroy Checking Yet!) */ LogIn( (LPSTR)"APICALL:OpenComm LPCSTR+UINT+UINT+", pp1, pp2, pp3 ); /* ** Call the API! */ RestoreRegs(); GrovelDS(); r = OpenComm(pp1,pp2,pp3); UnGrovelDS(); SaveRegs(); /* ** Log Return Code & OUT Parameters (No Create/Destroy Checking Yet!) */ LogOut( (LPSTR)"APIRET:OpenComm int++++", r, (short)0, (short)0, (short)0 ); RestoreRegs(); return( r ); }
//--------------------------------------------------------------- // Description: // Attept to open a com port. // portnum - number 0 to MAX_PORTNUM-1. This number is provided to // indicate the symbolic port number. // port_zstr - the string of the port to be used // Returns FALSE if unsuccessful and TRUE if successful. // SMALLINT OpenCOM(int portnum, char *port_zstr) { int i; for(i=0;i<4;i++) port[i] = port_zstr[i]; // Check if port has already been opened if (ComID[portnum] < 0) // Not opened { // Obtain port id ComID[portnum] = OpenComm(port_zstr,1024,1024); if (ComID[portnum] < 0) { OWERROR(OWERROR_GET_SYSTEM_RESOURCE_FAILED); return FALSE; } } else { return TRUE; // Already opened } if(!SetupCOM(portnum,CBR_9600)) // Reset unsuccessful { CloseCOM(portnum); OWERROR(OWERROR_SYSTEM_RESOURCE_INIT_FAILED); return FALSE; } return TRUE; }
bool CStrainDevice::InitComm(const char *config_file) { if (config_file) { m_strIniFile = config_file; } if (_access(m_strIniFile.GetString(), 0) != 0) { ASSERT(false); fprintf(stderr, "%s is non-exist!\n", m_strIniFile.GetString()); return FALSE; } char com[10]; DWORD baud = 0; DWORD dataSize = 0; DWORD parity = 0; DWORD stopBit = 0; ReadConfig(com, baud, dataSize, parity, stopBit, config_file); BOOL bOk = OpenComm(com); if (bOk) { SetupComm(baud, dataSize, parity, stopBit); } //_beginthreadex(NULL, 0, KeyboardThread, this, CREATE_SUSPENDED, NULL); //m_hReceiveThread = CreateThread(NULL, 0, LPCMonitorThread, this, CREATE_SUSPENDED, &m_dwThreadID); return bOk == TRUE; }
BOOL TSerialConnection :: Open ( void ) { TConnection :: Open ( ) ; DeviceId = OpenComm ( ConnectionParameters -> Serial. PortName, RECEIVE_BUFFER_SIZE_SERIAL, SEND_BUFFER_SIZE_SERIAL ) ; if ( DeviceId < 0 ) return ( FALSE ) ; memset ( & ComDCB, 0, sizeof ( ComDCB ) ) ; ComDCB. Id = DeviceId ; ComDCB. BaudRate = ( WORD ) ConnectionParameters -> Serial. Speed ; ComDCB. ByteSize = ConnectionParameters -> Serial. DataBits ; ComDCB. Parity = ConnectionParameters -> Serial. Parity ; ComDCB. StopBits = ConnectionParameters -> Serial. StopBits ; // Remarque TRES IMPORTANTE sur XoffLim et XonLim : // Il est absolument nécessaire d'assigner à ces champs une valeur bien // inférieure aux tailles des files de transmission/reception. // Pourquoi ? Lorsque la file d'attente du PC est pleine, il envoie un // caractère XOFF. Mais durant cet envoi, Unix continue de balancer ses // caractères vers le PC... caractères qu'il ne peut que perdre, puisqu'il // a déjà signalé qu'il n'en voulait plus (au moyen du XOFF). // En taillant ces valeurs au plus bas, on est assuré de ne pas avoir de // perte. // Autre remarque TRES importante : si fBinary n'est pas à 1, le caractère // EOFChar est reconnu. Par défaut, on le meyt à zéro. // Dans ces conditions, la réception du caractère 0 est donc reconnue comme // End of Data. La fonction GetCommError ne retourne aucun statut d'erreur, // et ReadComm satisfait toutes les demandes de lectures (quand bien même // il n'y a pas de données en attente). La seule manière possible de s'en // sortir semble être de fermer et de rouvrir le port... ou de mettre // fBinary à 1. ComDCB. fOutX = 1 ; ComDCB. fInX = 1 ; // Pour le XON-XOFF ComDCB. fRtsDisable = 1 ; ComDCB. fDtrflow = 1 ; ComDCB. fBinary = 1 ; ComDCB. XonLim = 0 ; ComDCB. XoffLim = RECEIVE_BUFFER_SIZE_SERIAL / 20 ; ComDCB. XonChar = XON ; ComDCB. XoffChar = XOFF ; if ( SetCommState ( & ComDCB ) < 0 ) return ( FALSE ) ; CharactersReceived = 0 ; Origin = 0 ; return ( TRUE ) ; }
/* 打开刷卡器串口 */ int CComInit::OpenCardComm(int ncom) { m_cCardComm.Format(_T("%d"),ncom); if(m_hComReadCard!=INVALID_HANDLE_VALUE) { CloseHandle(m_hComReadCard); m_hComReadCard = INVALID_HANDLE_VALUE; } if(ncom==0)return 0; m_hComReadCard = OpenComm(ncom); if(m_hComReadCard != INVALID_HANDLE_VALUE) { return 1; } else { m_cCardComm = L"0"; return -1; } }
/* 打开呼叫器串口 */ int CComInit::OpenWndScreen(int ncom) { m_cWndComm.Format(_T("%d"),ncom); if(m_hComWndScreen != INVALID_HANDLE_VALUE) { CloseHandle(m_hComWndScreen); m_hComWndScreen=INVALID_HANDLE_VALUE; } if(ncom== 0) return 0; m_hComWndScreen = OpenComm(ncom); if(m_hComWndScreen != INVALID_HANDLE_VALUE) { return 1; } else { m_cWndComm = L"0"; return -1; } }
int XTTY::Connect(BOOL fConnect) { if (fConnect) { // オンラインにする if (m_fConnect) // 既にオンライン? return 0; // 何もせずに終わる m_idComDev = OpenComm("COM2", 1024, 128); if (m_idComDev < 0) { // オープンに失敗? OpenComm_Error(m_idComDev); return -1; } DCB dcb; GetCommState(m_idComDev, &dcb); dcb.BaudRate = 57600; dcb.ByteSize = 8; dcb.Parity = NOPARITY; dcb.StopBits = ONESTOPBIT; SetCommState(&dcb); GetCommState(m_idComDev, &dcb); EnableCommNotification(m_idComDev, m_hwnd, 80, -1); EscapeCommFunction(m_idComDev, SETDTR); m_fConnect = TRUE; } else { // オフラインにする if (!m_fConnect) // 既にオフライン? return 0; // 何もせずに終わる EscapeCommFunction(m_idComDev, CLRDTR); CloseComm(m_idComDev); m_fConnect = FALSE; } return 0; }
void main (int argc, char *argv[]) { cout << "Squirrel 1.16/release, Adaptive answer Service for USR Voice modems" << endl; cout << "Copyright (c)2000 Eugeniy Gryaznov, Compiled on 02.05.00 at 21:09" << endl; if(argc<2) { cout << " Use <squirrel.exe> <action> [<action param>] [switches]" << endl; cout << " action: PLAY,REC,MAILER,MAIN" << endl; cout << " PLAY f.gsm Play file to speaker(modem)" << endl; cout << " REC f.gsm Record from microphone(modem) to file" << endl; cout << " MAILER Mailer compatible mode" << endl; cout << " MAIN Run in master mode" << endl; cout << " CONV f.gsm Convert GSM ->WAV" << endl; cout << " switches: [/L] [/D] [/P]" << endl; cout << " /L switch Playing/Recording device" << endl; cout << " /D switch Show debug info" << endl; cout << " /P switch close/real_close port" << endl; cout << " /B switch 8/16 bit wave output" << endl; cout << " Ex: squirrel play allo.gsm /L /D" << endl; cout << " squirrel main" << endl; ErrorExit(0,"Help screen"); } // Get default CTL name char ctl[128]; char *ext = "CTL"; strcpy(ctl,argv[0]); strcpy(ctl+strlen(ctl)-3,ext); SetDefault(); // Check ARGV int Task = 0, swch = 0; // 1 - PLAY, 2 - REC, 3 - MAILER, 4 - MAIN char TParam[128],fname[128],*outw; int postdo = 0; // Get task type if (strcmp(strupr(argv[1]),"PLAY")==0) { strcpy(TParam,argv[2]);Task=1; } else if (strcmp(strupr(argv[1]),"REC")==0) { strcpy(TParam,argv[2]);Task=2; } else if (strcmp(strupr(argv[1]),"MAILER")==0) { strcpy(TParam,argv[2]);Task=3; } else if (strcmp(strupr(argv[1]),"MAIN")==0) { strcpy(TParam,argv[2]);Task=4; } else if (strcmp(strupr(argv[1]),"CONV")==0) { strcpy(TParam,argv[2]);Task=5; } else ErrorExit(1,"Unknown action"); if ((Task==1||Task==2||Task==5)&&argc==2) ErrorExit(1,"not enough params"); // Process switches for (int argnum=2;argnum<argc;argnum++){ if ((Task!=1&&Task!=2&&Task!=5)||argnum!=2){ if (strcmp(strupr(argv[argnum]),"/D")==0) swch|=1; else if (strcmp(strupr(argv[argnum]),"/L")==0) swch|=2; else if (strcmp(strupr(argv[argnum]),"/P")==0) swch|=4; else if (strcmp(strupr(argv[argnum]),"/B")==0) swch|=8; else ErrorExit(1,"Unknown switch"); } } cout << "TASK: "; switch(Task){ case 1: cout << "playing file (device <- " << TParam << ")" << endl;break; case 2: cout << "recording file (device -> " << TParam << ")" << endl;break; case 3: cout << "mailer mode" << endl;break; case 4: cout << "master mode" << endl;break; } if (Task<5){ // Read config + FIX switches ReadConfig(ctl); if (swch&1) cfg.debuginfo=(cfg.debuginfo+1)%2; if (swch&2) cfg.pln=(cfg.pln+1)%2; if (swch&4) cfg.realcl=(cfg.realcl+1)%2; if (swch&8) cfg.wav8bit=(cfg.wav8bit+1)%2; // Open COMPort OpenComm(cfg.baud,cfg.ioport,cfg.irq); if(prtst!=-1) ErrorExit(3,"Communication port not found"); // Init screen StartupScr(); // Init modem SendModemStr(&cfg.init,"Initializing modem"); SendModemStr(&cfg.voice,"Voice mode"); } // Start Log if (Task==3||Task==4){ struct time _t; struct date _d; gettime(&_t);getdate(&_d); write_log("\n -- executed on "); write_log_num(_d.da_day);write_log("."); write_log_num(_d.da_mon);write_log("."); write_log_num(_d.da_year);write_log(" at "); write_log_num(_t.ti_hour);write_log(":"); write_log_num(_t.ti_min);write_log(" --\n"); } // Main work switch(Task){ case 1: PlayFile(TParam); break; case 2: cfg.wavout=0; RecFile(TParam,0); break; case 3: if (!cfg.gsmframe) ErrorExit(78,"mailer mode require USE_GSM=1"); cfg.up=0;cfg.pln=0; if (cfg.useaon&1){ AON(); } else { if (cfg.hook){ SendModemStr(&cfg.offhook,"Offhook"); delay(cfg.wallo); } } PlayFile(cfg.sallo); if (cfg.loglev&2) write_log("detecting\n"); switch (Detect()){ case 1: // Modem CreateFlag(cfg.ata); SendModemStr(&cfg.data,"Data mode"); SendModemStr(&cfg.mailinit,"Initializing modem to connect"); write_log("Detected: MODEM\n"); ErrorExit(0,"modem detected"); break; case 2: // Voice write_log("Detected: VOICE\n"); PlayFile(cfg.swait); for (int curring=0;curring<cfg.RTL;curring++){ if (!kbhit()){ if (strlen(cfg.soundfl)) CreateFlag(cfg.soundfl); else sound(cfg.khz); SendModemStr(&cfg.beep,"Beep"); nosound(); } if (kbhit()) break; if (curring+1!=cfg.RTL) delay(cfg.delayring); } ch=0;while (kbhit()) ch=getch(); if (cfg.auto_detect&&ch!=27&&ch!=32){ // check if voice present cout << " ! auto : speach in line" << endl;FixLine(); if (cfg.loglev&2) write_log("detecting\n"); ch=0;cfg.limit=cfg.auto_detect; if ((ch=Detect())==2) ch=32; if (ch==3||ch==4) break; } if (ch!=27) if (ch==32){ cout << " ! autoanswer skipped" << endl;FixLine(); write_log("autoanswer skipped\n"); postdo=1; } else { PlayFile(cfg.sauto); SendModemStr(&cfg.abeep,"aBeep"); generate_name(fname); write_log("Recording: ");write_log(fname);write_log("\n"); RecFile(fname,cfg.rec_time); } break; case 3: write_log("Detected: BUSY\n");break; case 4: write_log("Detected: DIAL TONE\n");break; } SendModemStr(&cfg.onhook,"Onhook"); break; case 4: int wring; char rng[100];cfg.up=0;cfg.pln=0; while(kbhit()) getch(); if (cfg.gsmframe==0&&cfg.useaon!=0) ErrorExit(73,"AON require USE_GSM=1"); while(!kbhit()){ cout << " Waiting for RING ...";rng[0]=0; while(!kbhit()&&strstr(rng,"RING")==NULL){ while(ReadComm(ch)){ rng[strlen(rng)+1]=0; rng[strlen(rng)]=ch; if (strlen(rng)==95) rng[0]=0; } } if (!kbhit()){ cout << endl;FixLine(); cout << " ! RING ."; for(wring=0;wring<(cfg.ring-1);wring++){ if (!WaitFor("RING",7,cfg.debuginfo)) { cout << " <no more rings>" << endl;FixLine();wring=0;break;} else cout << "."; } } if (!kbhit()&&wring){ // Wait cfg.ring cout << endl;FixLine(); if (cfg.useaon&2){ AON(); } else { SendModemStr(&cfg.offhook,"Offhook"); delay(cfg.wallo); } cfg.up=0; PlayFile(cfg.sauto); SendModemStr(&cfg.abeep,"aBeep"); generate_name(fname); RecFile(fname,cfg.rec_time); SendModemStr(&cfg.onhook,"Onhook"); SendModemStr(&cfg.init,"Initializing modem"); SendModemStr(&cfg.voice,"Voice mode"); while(kbhit()) getch(); } } cout << endl;FixLine(); while(kbhit()) getch(); break; case 5: // Open files if (swch&8) cfg.wav8bit=(cfg.wav8bit+1)%2; fp=fopen(TParam,"rb"); if (fp==NULL) ErrorExit(93,"error: .gsm input"); outw=TParam; cout << "GSM->WAV converting: " << TParam << " -> "; while (strchr(outw,'\\')!=NULL) outw=strchr(outw,'\\'); while (strchr(outw,'/')!=NULL) outw=strchr(outw,'/'); if (strlen(outw)==0) ErrorExit(153,"out name error"); if (strchr(outw,'.')!=NULL) *strchr(outw,'.')=0; strcat(strlwr(TParam),".wav"); cout << TParam;if(cfg.wav8bit) cout << " (8bit)";cout << endl; if (!Start_GSM_WAV(TParam,cfg.wav8bit)){ cout << "output file error";exit(1);} while (fread(gsmb,1,33,fp)==33){ decode_block(gsmb,cfg.wav8bit); } // close file fclose(fp); Close_GSM_WAV(); ErrorExit(0,"OK"); } // Deinit SendModemStr(&cfg.data,"Data mode"); SendModemStr(&cfg.deinit,"Deinitializing modem"); if (postdo&&cfg.postspace){ cout << " ! Press any key to return to Mailer"; getch();sound(440);delay(5);nosound(); cout << endl;FixLine(); } // Close COMPort & Exit ErrorExit(0,"All ok"); }
void Worker::Initialize() { ReadCfgFile(); OpenComm(); }
int main(int argc,char *argv[]) { int comspeed ; int i, rc ; char comport[20] ; char wks[20] ; TimeLimit4D = 2000 ; // 2 second timeout on all commands Callback4D = Callback ; // NULL ; // Error_Abort4D = TRUE ; // abort on detected 4D Serial error if (argc == 1) { /* If no arguments we call the Usage routine and exit */ Usage(argv[0]); return 1; } strcpy(comport, argv[1] ) ; strupr(comport) ; if (argc <= 2) comspeed = BAUD_9600 ; else { for (i = 0; i < maxrates; i++) { itoa(baudrates[i], wks, 10) ; if (!strcmp(wks,argv[2])) break ; } if (i == maxrates) { printf("Invalid baud rate %s",argv[2]) ; return 1; } comspeed = i ; } // printf("%s %d\n", comport, comspeed) ; rc = OpenComm(comport, comspeed) ; if (rc != 0) { printf("Error %d Opening %s", /*syserrormessage(*/rc/*)*/, comport) ; return 2 ; } gfx_Cls() ; fFATtests = trymount() ; fmediatests = FALSE ; fimgtests = FALSE ; ftouchtests = FALSE ; floadtests = FALSE ; fsoundtests = FALSE ; sys_GetModel(wks) ; // length is also returned, but we don't need that here printf("Display model: %s\n", wks) ; putstr("Display model: ") ; putstr(wks) ; i = strlen(wks) ; if ( (wks[i] == 'T') || (wks[i-1] == 'T') ) ftouchtests = TRUE ; printf("SPE2 Version: %4.4x\n", sys_GetVersion()) ; printf("PmmC Version: %4.4x\n", sys_GetPmmC()) ; if (fFATtests) { if (RAWPartitionbase(&rawbase)) fmediatests = TRUE ; if ( (file_Exists(gfx2demodat) != 0) && (file_Exists(gfx2demogci) != 0) ) fimgtests = TRUE ; if ( (file_Exists(functest) != 0) && (file_Exists(functestg) != 0) && (file_Exists(functestd) != 0) ) floadtests = TRUE ; if (file_Exists(soundtest)) fsoundtests = TRUE ; } if (fFATtests) { printf("FAT Tests will be done\n") ; if (fmediatests) { if (file_Exists(gfx2demogci)) printf("Media tests will be done\n") ; else { printf("Media tests cannot be done, missing %s\n", gfx2demogci) ; fmediatests = FALSE ; } } else printf("Media tests cannot be done, no RAW Partition\n") ; if (fimgtests) printf("Image tests will be done\n") ; else printf("Image tests will not be done, missing %s or %s\n", gfx2demogci, gfx2demodat) ; if (floadtests) printf("Load tests will be done\n") ; else printf("Load tests will not be done, missing %s or %s or %s",functest, functestg, functestd) ; if (fsoundtests) printf("Sound tests will be done\n") ; else printf("Sound tests will not be done, missing %s\n", soundtest) ; } else { printf("FAT Tests cannot be done, either no uSD card or no FAT partition\n") ; printf("Neither will Media, Image, Load or Sound Tests\n") ; } if (ftouchtests) printf("Touch Tests will be done\n") ; else printf("Touch Tests will not be done, display doesn't appear capable\n") ; sleep(5000) ; gfx_Part1() ; // GFX Part 1 tests sleep(5000) ; gfx_Part2() ; // GFX Part 2 tests sleep(5000) ; text_Tests() ; // text tests sleep(5000) ; if (fFATtests) { FAT_Tests() ; sleep(5000) ; } if (fimgtests) { IMG_Tests() ; sleep(5000) ; } if (fmediatests) { Media_Tests() ; sleep(5000) ; } if (floadtests) { Function_Tests() ; sleep(5000) ; } if (ftouchtests) { Touch_Tests() ; sleep(5000) ; } if (fsoundtests) { Sound_Tests() ; sleep(5000) ; } setbaudWait(BAUD_115200) ; putstr("Hello at 115200\n") ; setbaudWait(BAUD_9600) ; putstr("Back to 9600\n") ; return 0; }
int main() { int rc; int firstx ; int firsty ; int x ; int y ; int state ; TimeLimit4D = 2000; Callback4D = errCallback; // abort on detected 4D Serial error Error_Abort4D = 1 ; comspeed = 9600; //WORD *x = 0x001A; //char *s = sys_GetModel(&x); //x = &0x001A; rc = OpenComm(SERIALPORT, comspeed); if (rc != 0) { printf("Error %d Opening: %s - %s\n", errno, SERIALPORT, strerror(errno)); exit(EXIT_FAILURE); } gfx_Cls() ; putStr("Touch Tests\n") ; printf("Touch Tests.\n") ; putStr("Please ensure Touch is only\ndetected in the Blue area") ; printf("Detecting touch in Region\n") ; touch_Set(TOUCH_ENABLE) ; touch_DetectRegion(100,100, 200, 200) ; gfx_RectangleFilled(100,100, 200, 200, BLUE) ; do {} while (touch_Get(TOUCH_STATUS) != TOUCH_PRESSED); touch_Set(TOUCH_REGIONDEFAULT) ; gfx_Cls() ; putStr("Draw.. Drawing stops\nwhen touch released\n") ; printf("Drawing\n") ; while(touch_Get(TOUCH_STATUS) != TOUCH_PRESSED) { // we"ll wait for a touch } firstx = touch_Get(TOUCH_GETX); // so we can get the first point firsty = touch_Get(TOUCH_GETY); while(state != TOUCH_RELEASED) { state = touch_Get(TOUCH_STATUS); // look for any touch activity x = touch_Get(TOUCH_GETX); // grab the x y = touch_Get(TOUCH_GETY); // and the y coordinates of the touch if (state == TOUCH_PRESSED) // if there"s a press { firstx = x; firsty = y; } if (state == TOUCH_MOVING) // if there"s movement { gfx_Line(firstx, firsty, x, y, BLUE); // but lines are much better firstx = x; firsty = y; } } putStr("Done!\n") ; touch_Set(TOUCH_DISABLE); return (EXIT_SUCCESS); }