开源改变世界

蓝牙串口桥无法建立连接 #31

推推 grbl 3年前 (2023-01-24) 185次浏览

关闭
mkeyno 打开了这个问题 2017 年 5 月 1 日 · 17条评论
关闭

蓝牙串口桥无法建立连接#31

mkeyno 打开了这个问题 2017 年 5 月 1 日 · 17条评论

注释

蓝牙串口桥无法建立连接 #31

你好@arkypita,我使用蓝牙模块在硬件和站之间建立串行桥,除了你的软件,我对所有 gcode 发送器都没有问题,它无法建立连接,知道可能是什么问题吗?

蓝牙串口桥无法建立连接 #31
所有者

我想你可能会遇到与#32相同的问题

为了帮助我解决这个问题,您必须向我提供确切的 grbl 版本,如$I命令和$10状态报告掩码设置的值所报告的那样。如果你能告诉我 grbl 在?命令中返回的实时状态字符串如何,那就更好了

您是否也可以尝试不使用蓝牙(因此使用直接 USB 电缆)以查看是否有任何区别

蓝牙串口桥无法建立连接 #31
作者

我测试了 .9j 和 1.1f,没有一个组合没有通过蓝牙串行桥连接,而它与 USB 串行(电缆)连接工作正常,仅供参考,$10=0(状态报告选项,掩码)
正如它在你的软件之前所说的不像另一个 gcode 发送者无法制作无线串口桥

蓝牙串口桥无法建立连接 #31
所有者
阿尔基皮塔 评论了 2017 年 5 月 1 日  

行!所以你告诉我,如果 LaserGRBL 通过电缆连接但它不能通过蓝牙工作,那么它可以正常工作,而其他软件通过电缆和蓝牙都可以正常工作。这是正确的?

因此,问题在于 .net(LaserGRBL 编程所使用的系统)如何处理 COM/Bluetooth 端口。

你能给我一些关于这个蓝牙连接的额外信息吗?您在 arduino 端使用哪个蓝牙模块?PC端是集成蓝牙还是外接模块?您是否使用特定的驱动程序/软件将蓝牙视为 COM 端口,或者它在 Windows 中是完全透明/自动的?LaserGRBL 在端口列表中显示正确的 COM 端口?确切的行为是什么?

由于这是一个我很难重现的问题,因为我没有蓝牙模块可以尝试,所以我能做的就是编写一个简单的诊断程序并发送给您。

我在谷歌上搜索有关 .net comport 和蓝牙的问题,但在不知道蓝牙适配器的具体型号的情况下,搜索不是很有效。

http://www.google.it/search?client=opera&q=.net+comport+bluetooth
http://www.google.it/search?client=opera&q=.net+comport+bluetooth+issues
http://www.google.it/search?client=opera&q= .net+comport+蓝牙+bug

蓝牙串口桥无法建立连接 #31
作者
凯诺 评论了 2017 年 5 月 1 日  

我使用 HC-6 来控制我的 Arduino 模块,它通过蓝牙协议通过 Standard Serial 与我的笔记本电脑 BT 配对,因此我可以通过像 Termite 或 realterm 这样的程序轻松打开它,
它可以被选择,但它似乎握手不成功

http://2.bp.blogspot.com/-ANqBbReXkt4/T99Bw9aJWDI/AAAAAAAAAI0/eBYdC4Yr5Eo/s1600/HC-06.png

蓝牙串口桥无法建立连接 #31
所有者

我已经发布了一个新版本的 LaserGRBL,它在会话日志文件中记录了任何连接问题和内部程序错误。

https://github.com/arkypita/LaserGRBL/releases/tag/v2.6.0

请更新到新版本,尝试连接 LaserGRBL(执行 2-3 次尝试)并打开会话日志文件。

蓝牙串口桥无法建立连接 #31

然后将您的会话日志复制并粘贴到此处。

蓝牙串口桥无法建立连接 #31
作者
凯诺 评论了 2017 年 5 月 2 日  

谢谢@arkypita为了您的关心,我安装了新软件,这里是它的反馈

5/2/2017 11:31:53 AM	SetStatus   	Machine status [Connecting]
5/2/2017 11:31:53 AM	OpenCom     	Open COM11ʕ @ 115200 baud
5/2/2017 11:31:53 AM	OpenCom     	System.IO.IOException: The port 'COM11ʕ' does not exist.
5/2/2017 11:31:53 AM	OpenCom     	   at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
5/2/2017 11:31:53 AM	OpenCom     	   at System.IO.Ports.SerialStream..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace)
5/2/2017 11:31:53 AM	OpenCom     	   at System.IO.Ports.SerialPort.Open()
5/2/2017 11:31:53 AM	OpenCom     	   at LaserGRBL.GrblCore.OpenCom()
5/2/2017 11:32:09 AM	SetStatus   	Machine status [Disconnected]

如您所见,蓝牙 COM 编号带有后缀字母“ʕ”,我不知道为什么?
蓝牙串口桥无法建立连接 #31

在这里,当它通过 USB 串口连接时,如您所见,连接的 COM 端口没有额外的后缀字符

5/2/2017 11:48:24 AM	SetStatus   	Machine status [Connecting]
5/2/2017 11:48:24 AM	OpenCom     	Open COM19 @ 115200 baud
5/2/2017 11:48:24 AM	SendImmediate	Send Immediate Command [24]
5/2/2017 11:48:25 AM	SetStatus   	Machine status [Alarm]
蓝牙串口桥无法建立连接 #31
所有者
阿尔基皮塔 评论了 2017 年 5 月 2 日  

谷歌搜索我用来读取可用的端口名称 (getportnames) 的函数的名称显示了社区在与蓝牙一起使用时发出的许多问题。这似乎是 WindowsXP 下的 .NET 框架的一个错误(但有人报告说 Windows 7 上有类似的问题)。

其中一个结果提出了一些解决问题的技巧。有些技巧是在程序方面(清理端口名称),有些是在用户方面(卸载-重新安装蓝牙驱动程序、regedit 技巧等)。

http://stackoverflow.com/questions/32040209/serialport-getportnames-returns-incorrect-port-names

如果您想测试 regedit 方式,请遵循本指南:

使用 regedit.exe 进入注册表。

  1. 导航到“HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM”
  2. 记下通信端口名称。
  3. 将“0”或任何字符附加到 comm 端口名称。
  4. 将 comm 端口名称改回步骤 3 中的名称。
蓝牙串口桥无法建立连接 #31
作者

@arkypita我最近发布了 windows 7 64bit,它与 windows xp 无关,以下是简单的 USB 通信,适用于本地 USB 串口和蓝牙串口,因为它提到 COM 端口名称出现了额外的字符,对于系统来说是未知的.IO。例程处理程序,我可以建议制作临时解决方案以在打开端口并再次测试之前删除最后一个字符

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.IO.Ports;

namespace Usb_Reader
{
    public partial class Form1 : Form
    {
        char oldString = '\0';
        
        StreamReader sr;
        public Form1()
        {
            InitializeComponent();
            comboBox1.Items.AddRange(SerialPort.GetPortNames());
        }

        private void btnconnect_Click(object sender, EventArgs e)
        {
            if (btnconnect.Text == "Connect")
            {
                if (comboBox1.SelectedIndex != -1)
                {
                    serialPort1.PortName = comboBox1.SelectedItem.ToString();
                    try
                    {
                        serialPort1.Open();
                        btnconnect.Text = "DisConnect";
                        panel1.Enabled = true;
                        timer1.Enabled = true;
                        try
                        {
                            timer1.Interval = int.Parse(interval.Text);
                        }
                        catch(Exception)
                        {
                            timer1.Interval = 100;
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }

                }
            }
            else
            {
                btnconnect.Text = "Connect";
                serialPort1.Close();
                panel1.Enabled = false;
                timer1.Enabled = false;
            }
        }

        private void txtwrite_KeyPress(object sender, KeyPressEventArgs e)
        {

            if (e.KeyChar.ToString() == "\r")
            {
                serialPort1.WriteLine(txtwrite.Text);
            }
        }

        private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            string data = serialPort1.ReadLine();
            if (data == "\r")
            {
                return;
            }
            StreamWriter sw = new StreamWriter("usb_in.txt");
            
            sw.Write(data);
            if (txtread.InvokeRequired)
            {
                txtread.Invoke(new MethodInvoker(delegate { txtread.Text = data; }));
            }
            sw.Close();
            
        }
        
        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                timer1.Interval = int.Parse(interval.Text);
            }
            catch (Exception)
            {
                timer1.Interval = 100;
            }
            File.Copy("php_in.txt", "php_in_Copy.txt",true);
            sr= new StreamReader("php_in_Copy.txt");
            string line = sr.ReadLine();
            if (line[0] != oldString)
            {
                txtwrite.Text = line;
                //if (txtwrite.InvokeRequired)
                //{
                //    txtwrite.Invoke(new MethodInvoker(delegate { txtwrite.Text = line; }));
                //}
                serialPort1.WriteLine(line);
                oldString = line[0];
            }
            sr.Close();
        }

        private void interval_KeyPress(object sender, KeyPressEventArgs e)
        {
            //int result = 0;
            //e.Handled = int.TryParse(interval.Text, out result);
        }
    }
}
蓝牙串口桥无法建立连接 #31
所有者

GetPortNames() 从位于 HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM 的注册表项中读取端口名称

有时 Windows 在此列表中的名称有误。如果此列表中的名称是错误的,GetPortNames 返回它们显然是错误的。

最好的解决方案是清理程序中的名称,因为编辑和修复注册表的能力需要高级技能,而且它不是确定的。

错误的名字有一个超过应有的随机最后一个字符。由于随机字符意味着它也可能是数字字符,因此删除所有非数字最终字符的简单解决方案不能涵盖所有情况。

删除非数值应该是第一遍。
第二遍是使用后备程序拦截System.IO.IOException: The port 'COM11ʕ' does not exist.并再次尝试删除一个字符,正如您所建议的那样。

我会尽快为您发布修复程序
感谢您的反馈?

蓝牙串口桥无法建立连接 #31
作者

感谢您的关心,但是正如您所看到的端口名称是正确的(如预期的那样),所以它必须是另一个原因,即 GetPortNames 返回错误的列表
蓝牙串口桥无法建立连接 #31

蓝牙串口桥无法建立连接 #31
所有者
阿尔基皮塔 评论了 2017 年 5 月 2 日  

你认为它是正确的,但也许不是。
我认为字符串后面的二进制数据不是很好的空终止,所以当在注册表和 GetPortNames() 之间复制时,该函数不知道字符串长度。

只需尝试将字符串“COM11”编辑为“FOO”之类的内容并保存,然后将“FOO”编辑回“COM11”并再次保存。现在字符串应该没问题了。

然后运行或重新启动 LaserGRBL,看看是否有所不同……我只是想看看它是否修复了!

蓝牙串口桥无法建立连接 #31
作者

您的第一个解决方案不起作用,但是当我编辑回原始名称时,一切正常,如下日志所示,我建议将列表框的属性更改为可编辑,这样我就可以在此类事件中编辑端口名称

5/2/2017 6:54:32 PM	SetStatus   	Machine status [Disconnected]
5/2/2017 6:54:34 PM	SetStatus   	Machine status [Connecting]
5/2/2017 6:54:34 PM	OpenCom     	Open FOO @ 115200 baud
5/2/2017 6:54:34 PM	OpenCom     	System.ArgumentException: The given port name does not start with COM/com or does not resolve to a valid serial port.
5/2/2017 6:54:34 PM	OpenCom     	Parameter name: portName
5/2/2017 6:54:34 PM	OpenCom     	   at System.IO.Ports.SerialStream..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace)
5/2/2017 6:54:34 PM	OpenCom     	   at System.IO.Ports.SerialPort.Open()
5/2/2017 6:54:34 PM	OpenCom     	   at LaserGRBL.GrblCore.OpenCom()
5/2/2017 6:55:22 PM	SetStatus   	Machine status [Disconnected]
5/2/2017 6:55:26 PM	Program     	------------ PROGRAM STOP ------------

5/2/2017 6:55:33 PM	Program     	------------ PROGRAM START ------------
5/2/2017 6:55:35 PM	SetStatus   	Machine status [Disconnected]
5/2/2017 6:55:39 PM	SetStatus   	Machine status [Connecting]
5/2/2017 6:55:39 PM	OpenCom     	Open COM11 @ 115200 baud
5/2/2017 6:55:41 PM	SendImmediate	Send Immediate Command [24]
5/2/2017 6:55:41 PM	SetStatus   	Machine status [Idle]

蓝牙串口桥无法建立连接 #31
所有者
阿尔基皮塔 评论了 2017 年 5 月 2 日  

您原来的 COM11 以错误的格式存储在注册表中,如果您看到 COM11 也是如此。

当然“FOO”一定不行!“FOO”它是一个与任何其他字符串一样的字符串(FOO,PIPPO,YOURNAME。John,1234),它仅用于更改 COM11 并保存……不要测试/使用它:-)

序列edit as “foo” -> save -> edit as “COM11” -> save it again,确保将COM11另存为新字符串并覆盖旧的虚拟值。

arkypita 添加了引用此问题的提交 2017 年 5 月 2 日

蓝牙串口桥无法建立连接 #31
所有者

版本 v2.6.2 修复了这个错误/问题

https://github.com/arkypita/LaserGRBL/releases/tag/v2.6.2

蓝牙串口桥无法建立连接 #31
所有者

我有一个问题问你@mkeyno

如果我想在我的雕刻机中添加一个蓝牙模块,我可以简单地购买一个像这样的 arduino 模块(见链接)并连接电源、tx 和 rx 等等,或者我必须在 arduino grbl sketch 中写一些代码来初始化蓝牙板?

http://www.ebay.it/itm/Modulo-HC-06-scheda-bluetooth-4-pin-wireless-RF-transceiver-module-arduino-/222008015892?hash=item33b0b57c14:g:VK8AAOSwpzdWqTMZ

蓝牙串口桥无法建立连接 #31
作者
凯诺 评论了 2017 年 5 月 17 日  

@arkypita 只需连接引脚,不需要额外的编程,这就是为什么它被称为桥接器,但是我打算使用 ESP8266 而不是 BT,因为它比简单的串行透明具有更多的功能,在laseweb4中也是如此,它在 ESP 端使用 websocket 服务器来创建串行桥,我想知道你是否有未来的计划,我认为它需要你的软件上的 websocket 客户端,例如以下 lib

https://websocket4net.codeplex.com/
https://github.com/sta/websocket-sharp
https://msdn.microsoft.com/en-us/library/system.net.websockets.clientwebsocket(v=vs .110).aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1
http://stackoverflow.com/questions/30523478/connecting-to-websocket-using-c-sharp-i-can -connect-using-javascript-but-c-sha
https://codereview.stackexchange.com/questions/41591/websockets-client-code-and-making-it-production-ready

顺便说一句,关于这个话题,当互联网连接不可用时几乎没有例外
蓝牙串口桥无法建立连接 #31

调试

System.Net.WebException was unhandled
  Message=The remote name could not be resolved: 'lasergrbl.com'
  Source=System
  StackTrace:
       at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request)
       at System.Net.WebClient.DownloadString(Uri address)
       at System.Net.WebClient.DownloadString(String address)
       at LaserGRBL.GitHub.CheckSite(String site)
       at LaserGRBL.GitHub.AsyncCheckVersion(Object foo)
       at System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack)
       at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state)
  InnerException: 

蓝牙串口桥无法建立连接 #31
所有者

感谢您提供的信息和提示,
我刚刚订购了我的蓝牙 HC6 模块:-)

在最新版本中也修复了错误

喜欢 (0)