顺宗 2024-06-03 17:22 采纳率: 70%
浏览 5
已结题

触摸屏c语言的实现问题

步科触摸屏宏指令
这个数组写不进去触摸屏地址

#include "macrotypedef.h"
#include "math.h"
 
int MacroEntry()
{
    // 定义配方名称缓冲区和参数缓冲区
    signed short recipeNameBuf[12] = {0};
    signed short recipeParamBuf[27] = {0};
    signed short Buf[12] = {0};
    signed short Buff[27] = {0};
     signed short  i
 // 确定当前配方编号
    int currentRecipeNumber = LW130;
  if (currentRecipeNumber != 0)
 
    // 读取当前配方名称和参数
    ReadLocal("RW", 0, 12, (void*)recipeNameBuf, 0);
    ReadLocal("RL", 400, 27, (void*)recipeParamBuf, 0);
 
    {
    // 计算配方名称和参数的写入地址
    int recipeNameStartAddress = 20 + (currentRecipeNumber - 1) * 100;
    int recipeParamStartAddress = 50 + (currentRecipeNumber - 1) * 100;
 
    // 写入配方名称和参数
    WriteLocal("RW", recipeNameStartAddress, 12, (void*)recipeNameBuf, 0);
    WriteLocal("RW", recipeParamStartAddress, 27, (void*)recipeParamBuf, 0);
    }




    // 确定当前选择的模型编号
    int currentModelNumber = LW132;
 
    // 判断 LW132 是否不等于 0
    if (currentModelNumber != 0)
    {
        // 计算模型名称和参数的读取地址
        int modelNameStartAddress = 20 + (currentModelNumber - 1) * 100;
        int modelParamStartAddress = 50 + (currentModelNumber - 1) * 100;
 
        // 读取模型名称和参数
        ReadLocal("RW", modelNameStartAddress, 12, (void*)Buf, 0);
        ReadLocal("RW", modelParamStartAddress, 27, (void*)Buff, 0);
 
        // 写入模型名称和参数
        WriteLocal("RW", 0, 12, (void*)Buf, 0);
        WriteLocal("RL", 400, 27, (void*)Buff, 0);
    }
 
    return 0;
}
  • 写回答

3条回答 默认 最新

  • 阿里嘎多学长 2024-06-03 17:22
    关注

    以下内容由CHATGPT及阿里嘎多学长共同生成、有用望采纳:


    从您提供的代码片段来看,您在尝试将数据写入步科触摸屏的特定地址时遇到了问题。代码中确实存在一些潜在的问题,我将为您指出这些问题并提供可能的解决方案。

    代码中的问题:

    1. 语法错误:变量 i 后面缺少分号。
    2. 逻辑错误currentRecipeNumber 的检查没有放在 if 语句中。
    3. 可能的数据类型问题:在 WriteLocalReadLocal 函数中使用 signed short 作为缓冲区类型,需要确保触摸屏的API支持这种数据类型。
    4. 可能的API使用问题WriteLocalReadLocal 函数的使用需要根据步科触摸屏的API文档来确保正确性。

    解决方案:

    1. 修复语法错误: 添加 i 变量后面的分号。
    signed short i;
    
    1. 修复逻辑错误: 将 currentRecipeNumber 的检查放入 if 语句中。
    if (currentRecipeNumber != 0) {
        // 读取当前配方名称和参数
        // ...
    }
    
    1. 检查数据类型: 确保 signed short 是触摸屏API所支持的数据类型。如果不确定,可以查阅API文档或联系技术支持。

    2. 检查API使用: 根据步科触摸屏的API文档,确保 WriteLocalReadLocal 函数的使用是正确的。特别是参数传递和地址计算部分。

    示例代码:

    #include "macrotypedef.h"
    
    int MacroEntry()
    {
        // 定义配方名称缓冲区和参数缓冲区
        signed short recipeNameBuf[12] = {0};
        signed short recipeParamBuf[27] = {0};
        signed short Buf[12] = {0};
        signed short Buff[27] = {0};
        signed short i; // 添加分号
    
        // 确定当前配方编号
        int currentRecipeNumber = LW130;
        if (currentRecipeNumber != 0)
        {
            // 读取当前配方名称和参数
            ReadLocal("RW", 0, 12, (void*)recipeNameBuf, 0);
            ReadLocal("RL", 400, 27, (void*)recipeParamBuf, 0);
    
            // 计算配方名称和参数的写入地址
            int recipeNameStartAddress = 20 + (currentRecipeNumber - 1) * 100;
            int recipeParamStartAddress = 50 + (currentRecipeNumber - 1) * 100;
    
            // 写入配方名称和参数
            WriteLocal("RW", recipeNameStartAddress, 12, (void*)recipeNameBuf, 0);
            WriteLocal("RW", recipeParamStartAddress, 27, (void*)recipeParamBuf, 0);
        }
    
        // 确定当前选择的模型编号
        int currentModelNumber = LW132;
        if (currentModelNumber != 0)
        {
            // 计算模型名称和参数的读取地址
            int modelNameStartAddress = 20 + (currentModelNumber - 1) * 100;
            int modelParamStartAddress = 50 + (currentModelNumber - 1) * 100;
    
            // 读取模型名称和参数
            ReadLocal("RW", modelNameStartAddress, 12, (void*)Buf, 0);
            ReadLocal("RW", modelParamStartAddress, 27, (void*)Buff, 0);
    
            // 写入模型名称和参数
            WriteLocal("RW", 0, 12, (void*)Buf, 0);
            WriteLocal("RL", 400, 27, (void*)Buff, 0);
        }
    
        return 0;
    }
    

    参考资料:

    由于步科触摸屏的API文档和宏指令的详细信息通常由制造商提供,我建议您查阅步科官方提供的技术文档或联系他们的技术支持以获取更详细的帮助。通常,这些文档会包含API的详细说明、示例代码以及如何正确使用各种宏指令。

    如果您需要进一步的帮助,可以提供步科触摸屏的型号或更详细的API文档链接,以便我能提供更具体的建议。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 6月18日
  • 已采纳回答 6月10日
  • 创建了问题 6月3日

悬赏问题

  • ¥15 'Content-Type': 'application/x-www-form-urlencoded' 请教 这种post请求参数,该如何填写??
  • ¥15 找代写python里的jango设计在线书店
  • ¥15 请教如何关于Msg文件解析
  • ¥200 sqlite3数据库设置用户名和密码
  • ¥15 AutoDL无法使用docker install吗?
  • ¥15 cups交叉编译后移植到tina sdk的t113,只需要实现usb驱动打印机,打印pdf文件
  • ¥30 关于#wireshark#的问题:需要网络应用流量数据集需要做长度序列的实验,需要与应用产生的会话的数据包的长度,如视频类或者聊天类软件
  • ¥15 根据上述描述表示泥浆密度沿着管路的长度方向在不断变化,如何来表示泥浆密度随管路的变化(标签-matlab|关键词-流计算)
  • ¥21 matlab可以把图像数据转换为小波分析吗
  • ¥60 基于香农编码的图像压缩算法实现