Selaa lähdekoodia

fix: 添加Port_SetPort——激活端口句柄(漏掉的关键步骤)

lq 1 kuukausi sitten
vanhempi
commit
a1c4edebbe

+ 6 - 0
internal/modules/printer/service/csn_dll.go

@@ -60,6 +60,12 @@ func csn_OpenPRN(name string) (uintptr, error) {
 	return ret, nil
 }
 
+func csn_SetPort(handle uintptr) {
+	if csnDll != nil && handle != 0 {
+		csnDll.NewProc("Port_SetPort").Call(handle)
+	}
+}
+
 func csn_Close(handle uintptr) {
 	if csnDll != nil && handle != 0 {
 		csnDll.NewProc("Port_ClosePort").Call(handle)

+ 1 - 0
internal/modules/printer/service/service.go

@@ -47,6 +47,7 @@ func (s *PrintService) PrintTicket(printerID uint, lotName, channelCode, plateNo
 			return fmt.Errorf("打开打印机失败: %w (name=%s)", err, name)
 		}
 		useCSN = true
+		csn_SetPort(usbHandle) // 激活端口!
 		defer csn_Close(usbHandle)
 	}