寻网络/串行口通讯程序。150分

xiaohedou 2000-11-09 08:12:00
我想做一个网络发送/接收和串行口通讯程序的程序,那位有请给个例子。
如发送一个十六进制数串"0x1a,0x45,0x34,...",应该如何入手?

...全文
295 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaohedou 2001-01-04
  • 打赏
  • 举报
回复
感谢您的参与
xiaohedou 2000-12-11
  • 打赏
  • 举报
回复
感谢您的参与,我应该如何给您加分。。。
tchaikov 2000-11-11
  • 打赏
  • 举报
回复
tchaikov 2000-11-11
  • 打赏
  • 举报
回复
通过网络发送部分用TCP/IP Socket不是可以吗?
xiaohedou 2000-11-11
  • 打赏
  • 举报
回复
I have got a task to cotrol a machine and a serval pcs under WinNT system.
Command to machine link with a serial port and/or network,and other PCs
link with network.I also want to finf a man to help.

Thinks .
Good luck.
tchaikov 2000-11-11
  • 打赏
  • 举报
回复
唉!怎么同时发的。

能不能详细说一下 Network program 中有什么具体要求,我没搞清楚。
tchaikov 2000-11-11
  • 打赏
  • 举报
回复

http://www.csdn.net/dev/Delphi/
中VCL控件大集合中找"通讯"一栏中的前几个便是。
xiaohedou 2000-11-11
  • 打赏
  • 举报
回复
Think you. I just find a Delphi Example for serial port communication.
Now I want a Network program.
tchaikov 2000-11-11
  • 打赏
  • 举报
回复
哦,对不起,我看到这个帖子是在C/C++版的(外面现在显示怎么是DELPHI版了?),以为你在DOS下做.
Windows下用
CreateFile("\\\\..\\COM1",...)
不行吗?
在本站的程序员大本营中有很多这样的源码和例子,你可以去找找。
xiaohedou 2000-11-11
  • 打赏
  • 举报
回复
Thinks a lot,tchaikov.
But I want to use this program under WINNT/2000 system.I think 'outport' functions can't work correctly.
Think you for your help.
tchaikov 2000-11-09
  • 打赏
  • 举报
回复
/* Serial.h */


void closeserial(void);
void interrupt com_int (void);
int getccb(void);
void closeserial(void);
void initserial (void);
void i_disable (void);
void i_enable (int pnum);
void resvects (void);
void setvects (void);
void comon (void);
int SerialOut (char x);
int setserial (int Port,int Speed,int Parity,int Bits,int StopBit);

#define TRUE 1
#define FALSE 0
#define SBUFSIZ 0x2000

#define COM1BASE 0x3F8 /* base port for com1 */
#define COM2BASE 0x2F8 /* base port for com2 */

/* */
/* registers for serial port (not all used) */
/* */

#define TX 0 /* Transmit register */
#define RX 0 /* receive register */
#define IER 1 /* Interrupt Enable */
#define IIR 2 /* Interrupt ID */
#define LCR 3 /* Line control */
#define MCR 4 /* Modem control */
#define LSR 5 /* Line Status */
#define MSR 6 /* Modem Status */
#define DLL 0 /* Divisor Latch Low */
#define DLH 1 /* Divisor latch high */

/* */
/* Status values */
/* */

#define RCVRDY 0x01 /* Data ready flag */
#define OVRERR 0x02 /* Overrun error */
#define PRTYERR 0x04 /* Parity error */
#define FRMERR 0x08 /* Framing error */
#define BRKINT 0x10 /* Break interrupt */
#define XMTRDY 0x20 /* Transmit register empty */
#define XMTRSR 0x40 /* Tx shift register empty */

/* */
/* Status values for modem register */
/* */

#define CTS 0x10
#define DSR 0x20
#define RI 0x40
#define CD 0x80

#define DTR 0x01
#define RTS 0x02
#define OUT2 0x08

#define IMR 0x21
#define ICR 0x20
#define EOI 0x20
#define RX 0
#define IIR 2
#define RX_MASK 7
#define RX_ID 4

#define IRQ3 0xf7
#define IRQ4 0xef

#define MCR 4
#define IER 1
#define MC_INT 8
#define RX_INT 1
#define RX_MASK 7
#define RX_ID 4

#define BUFOVFL 1 /* buffer overflowed */

#define COM1 1
#define COM2 2

#define NO_PAR 0
#define EV_PAR 1
#define OD_PAR 2


---------------------------------------------------------------
/*
==========================
c.language/listings #115, from barryn, 8544 chars, Sat Aug 29 17:17:28 1987
--------------------------
TITLE: Communications routines in Turbo C

The following code shows how to take advantage of some of
the TurboC extensions to the C language to do asynchronous
communications (without having to write supporting assembly-
language routines). The code was supplied by Peter Ibbotson of
Borland. After the communications-related functions themselves,
you'll find a small main() section of code that uses those functions
to implement a rudimentary glass-TTY terminal program. (I say
rudimentary to mean that control characters are not recognized and
there are no file transfer, dialing directory, etc. features.)

First, here's Serial.C:
*/

/* SERIAL.C */

#include "serial.h"
#include <dos.h>
#include <stdio.h>
#include <conio.h>
#include <bios.h>
#include <process.h>

int SError;
int portbase=0;
void interrupt (*oldvects[2])();
char ccbuf[SBUFSIZ];
int startbuf=0;
int endbuf=0;

/* this does the hard work (handling interrupts) */

void interrupt com_int (void)

{ disable ();
if ((inportb (portbase+IIR) & RX_MASK)==RX_ID)
{ if (((endbuf+1) & 0x1fff)==startbuf)
SError=BUFOVFL;
ccbuf[endbuf++]=inportb (portbase+RX);
endbuf&=0x1fff;
};
outportb (ICR,EOI);
enable ();
}

/* this routine returns the currently value in the buffer */

int getccb(void)

{ int res;
if (endbuf==startbuf) return (-1);
res=(int) ccbuf[startbuf];
startbuf=(startbuf+1) % SBUFSIZ;
return (res);
}

void setvects (void)

{ oldvects[0]=getvect(0x0b);
oldvects[1]=getvect(0x0c);
setvect(0x0b,com_int);
setvect(0x0c,com_int);
}

void resvects (void)

{ setvect(0x0b,oldvects[0]);
setvect(0x0c,oldvects[1]);
}

void i_enable (int pnum)

{ int c;
disable();
c = inportb (portbase+MCR) ¦ MC_INT;
outportb (portbase+MCR,c);
outportb (portbase+IER,RX_INT);
c = inportb (IMR) & (pnum==2 ? IRQ3 : IRQ4);
outportb (IMR,c);
enable();
}

void i_disable (void)

{ int c;
disable ();
c=inportb (IMR) ¦ ~IRQ3 ¦ ~IRQ4;
outportb (IMR,c);
outportb (portbase + IER,0);
c=inportb (portbase+MCR) & ~MC_INT;
outportb (portbase+MCR,c);
enable ();
}

void comon (void)

{ int c,pnum;
pnum = portbase == COM1BASE ? 1 : 2;
i_enable (pnum);
c=inportb (portbase + MCR) ¦ DTR ¦ RTS;
outportb (portbase + MCR,c);
}

void initserial (void)

{ endbuf=startbuf=0;
setvects();
comon();
};

void comoff (void)

{ i_disable ();
outportb (portbase+MCR,0);
}

void closeserial(void)

{ comoff();
resvects();
};

/* this outputs a serial character */

int SerialOut (char x)

{ long timeout = 0x0000ffff;
outportb (portbase+MCR,OUT2¦DTR¦RTS);
/* wait for clear to send */
while ((inportb(portbase + MSR) & CTS)==0)
if ((--timeout)==0) return (-1);
timeout=0x0000ffff;
/* wait for outport register to clear */
while ((inportb(portbase+LSR) & DSR)==0)
if ((--timeout)==0) return (-1);
disable ();
outportb (portbase+TX,x);
enable ();
return (0);
}

/* this routine sets which port we are working with */

int SetPort (int Port)

{ int far * RS232_Addr;
int Offset;

switch (Port) /* sort out the base address */
{ case 1 : Offset=0x0000; break; /* only ports one & two allowed */
case 2 : Offset=0x0002; break;
default : return (-1);
};
RS232_Addr=MK_FP(0x0040,Offset); /* find out where the port is */
if (*RS232_Addr==0) return (-1); /* if it ain't there return (-1)*/
portbase=*RS232_Addr; /* otherwise set portbase */
return (0);
}

/* this routine sets the speed; will accept funny baud rates */

int SetSpeed (int Speed)

{ char c;
int divisor;
if (Speed==0) return (-1); /* avoid divide by zero */
else divisor=(int)(115200L/Speed);
if (portbase==0) return (-11);
disable ();
c=inportb (portbase+LCR);
outportb (portbase+LCR,(c¦0x80)); /* set DLAB */
outportb (portbase+DLL,(divisor & 0x00ff)); /* set divisor */
outportb (portbase+DLH,((divisor>>8)&0x00ff));
outportb (portbase+LCR,c);
enable();
return (0);
}

/* This routine set the LCR */

int SetOthers (int Parity,int Bits,int StopBit)

{ int temp;
if (portbase==0) return (-1);
if ((Parity<NO_PAR) ¦¦ (Parity>OD_PAR)) return (-1);
if ((Bits<5) ¦¦ (Bits>8)) return (-1);
if ((StopBit<1) ¦¦ (StopBit>2)) return (-1);
temp=Bits-5;
temp¦=((StopBit==1) ? 0x00 : 0x04);
switch (Parity)
{ case NO_PAR : temp ¦= 0x00; break;
case OD_PAR : temp ¦= 0x08; break;
case EV_PAR : temp ¦= 0x18; break;
}
disable(); /* turn off interrupts */
outportb (portbase+LCR,temp);
enable(); /* turn em back on */
return (0);
}

/* This routine sets the ports */

int setserial (int Port,int Speed,int Parity,int Bits,int StopBit)

{ if (SetPort(Port)==-1) return(-1);
if (SetSpeed(Speed)==-1) return(-1);
if (SetOthers(Parity,Bits,StopBit)==-1) return (-1);
return (0);
}

/* short demo */
/* this opens the ports and echos to screen until */
/* ESCape received */

main ()

{ int c;

if (setserial (COM1,2400,NO_PAR,8,1) ==-1) exit (1);
initserial();
printf("You're now in terminal mode. Press ESC to quit the program.\n\n");

do {
if (kbhit()) {
c = getch();
if (c==27)
break;
SerialOut(c);
}

if ((c=getccb())!=-1)
putchar (c);

} while (c!=27);

closeserial();
}
xiaohedou 2000-11-09
  • 打赏
  • 举报
回复
感谢所有参与的人!^o^
一个单片机串行数据采集及传输模块的设计.pdf 一个系统中多单片机之间的数据交换.pdf 一款基于凌阳61单片机的汽车弯道会车雷达设计.pdf 一种8位单片机中ALU的改进设计.pdf 一种rfid手持读写设备省电模式的实现.pdf 一种低成本的单片机数据采集系统.pdf 一种包装机械手充填重量的单片机检测系统.pdf 一种单检测器图像信号检测系统的设计.pdf 一种单片机在直流电动机调速系统中的利用.pdf 一种单片机在线仿真方法的实现.pdf 一种单片机结合CPLD自动控制升降旗系统.pdf 一种单片机综合实验系统的设计.pdf 一种单片机语音录入和播放系统设计.pdf 一种变波特率方式的单片机ISP设计.pdf 一种可用于器性能测试的恒流源.pdf 一种基于AT89C51单片机的直流调速控制装置.pdf 一种基于atmega8单片机的iccd亮度调节方案.pdf 一种基于avr单片机的监控系统的研究与实现.pdf 一种基于CPLD的单片机与PCI接口设计解决方案.pdf 一种基于Cygnal单片机的新型RTU.pdf 一种基于delphi和at89s52单片机的串行通讯模块的实现.pdf 一种基于MCS51单片机的数字冷端补偿方法.pdf 一种基于MSP430单片机的交流频率检测系统.pdf 一种基于msp430单片机的心电模块设计.pdf 一种基于MSP430单片机的日程管理系统.pdf 一种基于PIC系列单片机的SPWM逆变电源.pdf 一种基于SPCE061A单片机的信号发生器.pdf 一种基于单片机及CPLD测试平台的设计与实现.pdf 一种基于单片机和串行EEPROM的智能密码锁.pdf 一种基于单片机的ccd驱动电路设计.pdf 一种基于单片机的led控制器的硬件电路.pdf 一种基于单片机的半导体激光器电源控制系统的设计.pdf 一种基于单片机的压力检测系统.pdf 一种基于单片机的在线式ups的设计.pdf 一种基于单片机的数据采集及控制系统的设计.pdf 一种基于单片机的汽车电子点火系统的设计.pdf 一种基于单片机的温度监控系统设计.pdf 一种基于单片机的灯光调光控制系统开发.pdf 一种基于单片机的红外测控系统.pdf 一种基于单片机的节能断电保护电路设计.pdf 一种基于单片机的超声测距系统的设计.pdf 一种基于单片机通用口实现串行通信的方法.pdf 一种基于消息传递的单片机多条件多程序设计方法.pdf 一种基于等效采样技术的高速数据采集系统.pdf 一种实用单片机和cpld最小应用系统的设计.pdf 一种实用的单片机双CPU设计方案及其应用.pdf 一种小型水下运动目标定位系统的设计.pdf 一种数据采集与融合系统结构及其实例.pdf 一种新型SOC单片机在水平仪温度补偿的应用.pdf 一种新型体式单片机实验装置.pdf 一种新型单片机功率调强系统机及其C51实现.pdf 一种新型实用的MCS51单片机实验教具设计.pdf 一种新型集控智能无线连网的安防系统.pdf 一种无刷直流电动机锁相数字稳速驱动系统.pdf 一种无线传感器网络节点设计和通信协议研究(1).pdf 一种机器人线控制系统.pdf 一种材料局部机械强度检测系统的设计.pdf 一种简单方法实现基于STC89C52RC单片机的频率计.pdf 一种适用于单片机的语音编码算法及应用.pdf 一种面向社区医疗微型输液监测系统的设计.pdf 一种高精度数据采集无线传输系统硬件设计.pdf 一种高速折刀运动控制系统的设计与实现.pdf 三相异步电动机工作绕组温升的单片机检测.pdf 中小型养猪场风机调速系统.pdf 临界装置反应性加入速度测量系统设计.pdf 交流伺服电机的多波形旋转控制系统研究.pdf 交流伺服电机超低速运转的实现.pdf 交流电动机软起动控制器的设计.pdf 交流采样的设计与实现.pdf 人体短臂离心机实验台的显示控制系统.pdf 人工气候室监控系统的环境控制器研究.pdf 人造金刚石压机智能化压力测控系统设计.pdf 以msp430单片机为核心的同步发电机稳定性控制实验装置的研究.pdf 以单片机为核心的发电机控制器硬件设计.pdf 任务驱动法在单片机教学中的应用.pdf 偏磁式消弧线圈的动态调谐装置.pdf 免耕穴播播种机播种过程监测系统的研究.pdf 全电动注射成型机控制系统设计.pdf 全站仪动态测量的研究以及其与单片机在轨道式龙门吊实时检测中的应用.pdf 全组合式键盘电路构造方法.pdf 具有能量回馈制动功能的电动车控制器设计.pdf 内置SED1335控制器的液晶显示模块与单片机接口应用.pdf 农田气候信息采集系统中gsm模块的短信查询算法研究.pdf 凌阳单片机在电子导游器中的应用.pdf 切

1,593

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧