Private Sub hexSend()
创新互联是一家专注于成都网站设计、成都做网站和四川服务器托管的网络公司,有着丰富的建站经验和案例。
On Error Resume Next
Dim outputLen As Integer
Dim outData As String
Dim SendArr() As Byte
Dim TemporarySave As String
Dim dataCount As Integer
Dim i As Integer
outData = UCase(Replace(txtSend.Text, Space(1), Space(0)))
outData = UCase(outData)
outputLen = Len(outData)
For i = 0 To outputLen-1
TemporarySave = Mid(outData, i + 1, 1)
If (Asc(TemporarySave) = 48 And Asc(TemporarySave) = 57) Or (Asc(TemporarySave) = 65 And Asc(TemporarySave) = 70) Then
dataCount = dataCount + 1
Else
Exit For
Exit Sub
End If
Next
If dataCount Mod 2 0 Then
dataCount = dataCount - 1
End If
outData = Microsoft.VisualBasic.Left(outData, dataCount)
ReDim SendArr(dataCount / 2 - 1)
For i = 0 To dataCount / 2 - 1
SendArr(i) = Val("h" + Mid(outData, i * 2+1, 2))
Next
SerialPort1.Write(SendArr, 0, 1)
End Sub
修改几处就好用了。
绝对不行!基于x86处理器构架的程序,是不能在不是x86构架的单片机上运行的。
这个可以有,是51的,用到STC8A8K64S4A12上应该不成问题。
#include STC89.H
unsigned char tmp;
sbit shebei1=P1^0;//定义控制设备的IO口
sbit shebei2=P1^1;
sbit shebei3=P1^2;
sbit shebei4=P1^3;
sbit shebei5=P1^4;
sbit shebei6=P1^5;
void main()
{
TMOD = 0x20; // 定时器1工作于8位自动重载模式, 用于产生波特率
TH1 = 0xFD; // 波特率9600
TL1 = 0xFD;
SCON = 0x50; // 设定串行口工作方式
PCON = 0xef; // 波特率不倍增
TR1 = 1; // 启动定时器1
IE = 0x0; // 禁止任何中断
while(1)
{
if(RI) // 是否有数据到来
{
RI = 0;// 清接收标志
tmp = SBUF; // 暂存接收到的数据
switch(tmp )
{
case 0x22:shebei1=0;break;//关设备1
case 0x33:shebei1=1;break;//开设备1
case 0x44:shebei2=0;break;
case 0x55:shebei2=1;break;
case 0x66:shebei3=0;break;
case 0x77:shebei3=1;break;
case 0x88:shebei4=0;break;
case 0x99:shebei4=1;break;
// case 0xaa:shebei5=0;break;
// case 0xbb:shebei5=1;break;
// case 0xcc:shebei6=0;break;
// case 0xdd:shebei6=1;break;
case 0x17:shebei5=0;break;
case 0x18:shebei5=1;break;
case 0x19:shebei6=0;break;
case 0x20:shebei6=1;break;
}
}
}
}
void delayms(unsigned char ms)
// 延时子程序
{
unsigned char i;
while(ms--)
{
for(i = 0; i 120; i++);
}
}
一个需要.net框架,一个不需要,学单片机就不要 vb.net了,vb.net一般都用于企业级软件的开发,随着C#的普及,用 vb.net的也越来越少了。单纯用好vb脚本也很不错