快速,持续,稳定,傻瓜式
支持Mysql,Sqlserver数据同步

51单片机如何读取sql数据库

请联系QQ:1793040 索取软件

展开所有

您需要进行串行通信,将单片机的数据上传到计算机,并在计算机上写入主机。来自通信的数据可以存储在sql服务器的数据库中。

串行端口程序需要写在MCU端,而主机软件VB可以写在PC端。可以编写MSComm1控件。
通信示例如下
/>
Dim i作为整数

Dim a As整数
Dim t()作为字节

私人子Command1_Click()
如果Command1.Caption = \ quot;打开串口然后
” Shape1.Visible = True
Shape1.FillColor = \ HFF \
Shape1.BackColor = \ HFF \
Shape1.BorderColor = \ HFF \

Command2.Enabled =真实
Command3.Enabled =真实
Command1.Caption = \ quot;关闭串行端口\ quot;
” MSComm1.CommPort = 1″设置Set Com1端口
MSComm1.CommPort = Combo1.Text”设置Com1端口
如果MSComm1.PortOpen = False则
” MSComm1.Settings = \ quot; 4800,N,8 ,1 \\” 4800波特率 e799bee5baa6e997aee7ad94e59b9ee7ad9431333431373236 ,无奇偶校验,8个数据位,1个停止位
MSComm1.Settings = Combo2.Text \\ “,” \ Combo3.Text \ quot ;、 \ quot; \ Combo4.Text \ quot;,\ quot; \ Combo5.Text” 4800波特率,无奇偶校验,8个数据位,1个停止位

MSComm1.InputLen = 1″读取接收缓冲区的所有字符
MSComm1.InputLen = 5
MSComm1.InBufferSize = 5″将接收缓冲区设置为1024字节
MSComm1.OutBufferSize = 5″将发送缓冲区设置为512字节
MSComm1.SThreshold = 0″不触发发送事件
MSComm1.RThreshold = 1″接收缓冲区中的每个字符都会触发接收事件
MSComm1.PortOpen = True”打开串行端口
如果
MSComm1.OutBufferCount = 0结束空的发送缓冲区
MSComm1.InBufferCount = 0″空的接收缓冲区
Dim temp()作为字节
其他
” Option2.Value = False
” Option1.Value =假
” Shape1.Visible =假
Shape1.BackColor = \ H808080
Shape1.BorderColor = \ H808080
Shape1.FillColor = \ H808080

Command2.Enabled=假
” Command3.Enabled =假
MSComm1.PortOpen =假
Command1.Caption = \ quot;打开串口”

End If

End Sub

Private Sub Command2_Cl ick()
” Command2.Enabled = False
” Option2.Value =假
” Option1.Value =假

” Shape2.Visible =假
> MSComm1.OutBufferCount = 0″空的发送缓冲区
MSComm1.InBufferCount = 0 “空的接收缓冲区

” t(0)= \”; 255 \ quot;

>” MSComm1.Output = t

MSComm1.Output = Text2.Text
结束子

Private Sub Command3_Click()
Text1.Text = \ quot; \ quot;

End Sub

Private Sub Command5_Click()”退出
End
End Sub

Private Sub Command6_Click()
Text2.Text = \ quot; \ quot;
End Sub

私有Sub Command7_Click()
如果Command7.Value,则
” Command7。可见=假
Command1.Visible =真实
Command2.Visible =真实
Command3.Visible =真实
Command6.Visible =真实
Label1.Visible =真实
Label2.Visible =真实
Label3.Visible =真实
Label4.Visible =真实
Label5.Visible =真实
Label6.Visible =真实
Label7.Visible =真实
Combo1.Visible =真实
Combo2.Visib le =真实
Combo3.Visible =真实
Combo4.Visible =真实
Combo5.Visible =真实

Text1.Visible =真
Text2.Visible =真
Frame1.Visible =真
Frame2.Visible =假
” Command3.Visible =假
/>” Option1.Value = False
Shape1.Visible = True

其他
Label1.Visible =假
Label2.Visible =假
Label3.Visible =假
Label4.Visible =假
Label5。可见=假
Label6.Visible =假
Label7.Visible =假
Combo1.Visible =假
Combo2.Visible =假
Combo3.Visible =假
/> Combo4.Visible = False
Combo5.Visible = False
Command1.Visible = False
Command2.Visible = False
Command3.Visible = False
Text1.Visible =假
Text2.Visible =假
Frame1.Visible =假
Frame2.Visible =假
如果
结束子

私有Sub Form_Load()

MSComm1.InBufferCount = 0″清除发送缓冲区数据
MSComm1.OutBufferCount = 0″清除接收缓冲区数据
ReDim t(0)
t (0)= \ quot; 0 \\ u00;
Combo1.AddItem \ quot; 1 \\”
Combo1.AddItem \ quot; 2 \ quot;
Combo1.AddItem \ quot; 3 \\”
Combo1.AddItem \ quot; 4 \\”
” Combo1.Text = \ quot; 1 \ quot;
Combo2.AddItem \ quot; 300 \ quot;
Combo2.AddItem \ quot; 600 \ quot;
Combo2.AddItem \” 1200 \”
Combo2.AddItem \” 2400 \”
Combo2.AddItem \” 4800 \”
Combo2.AddItem \” 9600 \”
Combo2.AddItem \” 19200 \” Combo3.AddItem \ N \
Combo3.AddItem” O”
Combo3.AddItem E” E” Combo4.AddItem 8″ 8″ Combo4″。 AddItem \ quot; 7 \ quot;
Combo4.AddItem \ quot; 6 \ quot;
Combo5.AddItem \ quot; 1 \ quot;
Combo5.AddItem \ quot; 2 \ quot;
Combo5.AddItem \ quot; 3 \ quot;

End Sub

Private Sub MSComm1_OnComm()
Dim s1作为字符串
Dim s2作为字符串
选择Case MSComm1.CommEvent

Case comEventOverrun”数据丢失
Text_SEND.Text = \ quot; \ quot; “清除发送缓冲区
Text_RECV.Text = \ quot;”清空接收缓冲区
Text_SEND.SetFocus
Exit Sub
comEventRxOver”接收缓冲区溢出
Text_SEND.Text = \ quot”空发送缓冲区
Text_RECV.Text = \ quot; \ quot; “清除接收缓冲区
Text_SEND.SetFocus
退出子
案例comEventTxFull”发送缓冲区已满
Text_SEND.Text = \ quot; \ quot; “清除发送缓冲区
Text_RECV.Text = \ quot;”清除接收缓冲区
Text_SEND.SetFocus
退出子
案例comEvReceive”接收字符数据
变暗缓冲区作为变量
MSComm1.InputLen = 1
MSComm1.InputMode = comInputModeBinary”二进制传输
Buffer = MSComm1.Input
” Text1.Text =缓冲区(0)
” s2 =缓冲区(1)

Text1.Text = Text1.Text \(Val(MSComm1.Input))\ \ quot; \ quot;

其他案例

结束选择

结束子

私人子Option1_Click()

>结束子

展开所有

读取数据库中的信息应在PC上完成。

这与微控制器无关。

相关推荐

咨询软件
 
QQ在线咨询
售前咨询热线
QQ1793040