实验环境:wxFormBuilder v3.5 + python3.7.5 + MC9S12G128开发板
基本功能:控制开发板上的按键,模拟车辆移动的上下左右四个方位,通过can通信告诉上位机界面,车辆轨迹的移动方位;
1. python重新封装controlcan接口函数
参考本人写的文章:python调用32位的ControlCan.dll实现can报文的收发
2. 上位机程序开发过程中遇到的问题及解决思路
MC9S12G128开发板—实现按键发送CAN报文指示小车移动功能
本人写的下面这篇文章也记录了上位机程序开发过程中遇到的一些问题及解决思路:
MC9S12G128开发板—解决小车九宫格方位移动功能实现遇到的一些问题
2.1 问题Q1:界面卡死
解决界面卡死的方法请查看本人写的这篇文献,文章链接:https://blog.csdn.net/Logintern09/article/details/122448199
2.2 问题Q2:小车图像显示错位问题
原界面程序代码:
class MyFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, id=wx.ID_ANY, title=wx.EmptyString, pos=wx.DefaultPosition,
size=wx.Size(874, 656), style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL)
self.SetSizeHints(wx.DefaultSize, wx.DefaultSize)
bSizer = wx.BoxSizer(wx.VERTICAL)
bSizer4 = wx.BoxSizer(wx.VERTICAL)
bSizer8 = wx.BoxSizer(wx.HORIZONTAL)
m_choice1Choices = [u"索引0", u"索引1"]
self.m_choice1 = wx.Choice(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, m_choice1Choices, 0)
self.m_choice1.SetSelection(0)
bSizer8.Add(self.m_choice1, 0, wx.ALL, 5)
m_choice2Choices = [u"250Kbps", u"500Kbps"]
self.m_choice2 = wx.Choice(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, m_choice2Choices, 0)
self.m_choice2.SetSelection(0)
bSizer8.Add(self.m_choice2, 0, wx.ALL, 5)
self.m_button1 = wx.Button(self, wx.ID_ANY, u"连接", wx.DefaultPosition, wx.DefaultSize, 0)
bSizer8.Add(self.m_button1, 0, wx.ALL, 1)
m_radioBox1Choices = [u""]
self.m_radioBox1 = wx.RadioBox(self, wx.ID_ANY, u"", wx.DefaultPosition, wx.DefaultSize,
m_radioBox1Choices, 1, wx.RA_SPECIFY_COLS)
self.m_radioBox1.SetSelection(0)
bSizer8.Add(self.m_radioBox1, 0, wx.ALL, 5)
self.m_button2 = wx.Button(self, wx.ID_ANY, u"开始", wx.DefaultPosition, wx.DefaultSize, 0)
bSizer8.Add(self.m_button2, 0, wx.ALL, 1)
bSizer4.Add(bSizer8, 1, wx.EXPAND, 5)
bSizer9 = wx.BoxSizer(wx.VERTICAL)
self.m_textCtrl1 = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.Size(20, 200),
wx.TE_MULTILINE | wx.TE_READONLY | wx.TE_RICH2)
bSizer9.Add(self.m_textCtrl1, 0, wx.EXPAND, 20)
bSizer4.Add(bSizer9, 3, wx.EXPAND, 5)
bSizer.Add(bSizer4, 2, wx.EXPAND, 5)
bSizer1 = wx.BoxSizer(wx.HORIZONTAL)
self.m_bitmap1 = wx.StaticBitmap(self, wx.ID_ANY, wx.NullBitmap, wx.DefaultPosition, wx.DefaultSize, 0)
bSizer1.Add(self.m_bitmap1, 1, wx.EXPAND, 5)
self.m_bitmap2 = wx.StaticBitmap(self, wx.ID_ANY, wx.NullBitmap, wx.DefaultPosition, wx.DefaultSize, 0)
bSizer1.Add(self.m_bitmap2, 1, wx.EXPAND, 5)
self.m_bitmap3 = wx.StaticBitmap(self, wx.ID_ANY, wx.NullBitmap, wx.DefaultPosition, wx.DefaultSize, 0)
bSizer1.Add(self.m_bitmap3, 1, wx.EXPAND, 5)
bSizer.Add(bSizer1, 1, wx.EXPAND, 5)
bSizer2 = wx.BoxSizer(wx.HORIZONTAL)
self.m_bitmap4 = wx.StaticBitmap(self, wx.ID_ANY, wx.NullBitmap, wx.DefaultPosition, wx.DefaultSize, 0)
bSizer2.Add(self.m_bitmap4, 1, wx.EXPAND, 5)
self.m_bitmap5 = wx.StaticBitmap(self, wx.ID_ANY, wx.NullBitmap, wx.DefaultPosition, wx.DefaultSize, 0)
bSizer2.Add(self.m_bitmap5, 1, wx.EXPAND, 5)
self.m_bitmap6 = wx.StaticBitmap(self, wx.ID_ANY, wx.NullBitmap, wx.DefaultPosition, wx.DefaultSize, 0)
bSizer2.Add(self.m_bitmap6, 1, wx.EXPAND, 5)
bSizer.Add(bSizer2, 1, wx.EXPAND, 5)
bSizer3 = wx.BoxSizer(wx.HORIZONTAL)
self.m_bitmap7 = wx.StaticBitmap(self, wx.ID_ANY, wx.NullBitmap, wx.DefaultPosition, wx.DefaultSize, 0)
bSizer3.Add(self.m_bitmap7, 1, wx.EXPAND, 5)
self.m_bitmap8 = wx.StaticBitmap(self, wx.ID_ANY, wx.NullBitmap, wx.DefaultPosition, wx.DefaultSize, 0)
bSizer3.Add(self.m_bitmap8, 1, wx.EXPAND, 5)
self.m_bitmap9 = wx.StaticBitmap(self, wx.ID_ANY, wx.NullBitmap, wx.DefaultPosition, wx.DefaultSize, 0)
bSizer3.Add(self.m_bitmap9, 1, wx.EXPAND, 5)
bSizer.Add(bSizer3, 1, wx.EXPAND, 5)
self.SetSizer(bSizer)
self.Layout()
self.Centre(wx.BOTH)
解决思路:后面采用面板Panel重新放置StaticBitmap控件的方式成功解决了上图所示的小车图片显示错位问题。
3. 上位机程序源码下载地址
python实现九宫格的车辆路径轨迹上位机程序下载地址:https://download.csdn.net/download/Logintern09/87800717
参考文献
wxpython中多线程的实现:https://wenku.baidu.com/view/e3a978f2c2c708a1284ac850ad02de80d4d806a5.html
如何使用pyinstaller打包32位的exe程序:
http://www.zzvips.com/article/174280.html